/**
 * @author jouyang
 */

if(typeof(push)!="undefined"&&typeof(push.proxy) != "undefined"){     // QS chart.
	GB_ChartDataManager.option.needUpdateIntradyData = true;
}
var RTChartComponent = function(mainticker,reg,language){
	this._title = "Chart";
	this.timezone = "";
	this.securityType = [1,10,2];  // 1: stock,close fund; 10:indexs, 2: options.
	this.autoTitle = true;
    this.defaultFrequencyMenuCfg = {intraday:true,history:true,customer:true};
	this.requencyMenuCfg = {intraday:true,history:true,customer:true};// for save
    /*this.extendConfig = {
        indicators: {
            SMA: "",
            EMA: "",
            SMAV: "",
            BBands: "",
            PSAR: "",
            MACD: "",
            RSI: "",
            ROC: "",
            WillR: "",
            SStochastic: "",
            FStochastic: "",
            PChannel: "",
            MAE: "",
            Momentum: "",
            ULT: "",
            DMI: "",
            MFI: "",
            OBV: "",
            VAcc: "",
            UDRatio: "",
            VBP: "",
            Volume: "",
            VPlus: "",
            FVolatility: "",
            WMA: "",
            AccDis: "",
            Mass: "",
            Volatility: "",
            ForceIndex: "",
            ATR: "",
            Keltner: "",
            PrevClose: ""
        }
    };*/
    this.dataUrl = {
		getTickerInfoURL :this.protocol+"qt.morningstar.com/switchservice/getids.ashx?d=1&", // get ticker information url.
		relatiedSecURL :this.protocol+"quote.morningstar.com/stock/competitorRawList.ashx?out=1"
	}
    //globalization parameters
    this.region = (reg==null?"USA":reg);
    this.lan = (language==null?"en_US":language);
    this.cur="USD";
	 // system configure  
    this.latestTradeDate = new Date();
    this.tickerMaxNum = 7;  // the maximum compaire ticker in a chart.
    this.sDates={iMin:null,sMin:null,lMin:null,d:null,w:null,m:null};// the start date for daily data,weekly data.monthly data.
    this.fillColors = typeof(QS_Style)=="undefined"?{pChart:"#c9d2dd",vChart:"#2f4880",sChart:"#d9dfeb"}:QS_Style.chart.fillColors;
	this.colors={borderColor:null,gridColor:typeof(QS_Style)=="undefined"?"#dddddd":QS_Style.flot.grid.tickColor,lableFontColor:typeof(QS_Style)=="undefined"?"#545454":QS_Style.flot.grid.color};
	this.objName; // the name of  self instance variable of RTChartComppnent.
    //var chartObj = this; // self instance variable 
	// the size parameters for chart component.
	this.chartWidth = 760;
	this.outHeight=0;
    this.pChartHeight=300;
    this.vChartHeight=60;
    this.miniChartHeight = 26;
	this.wheelNum = 0;
    this.minW = 300;  // the minimum of width of the chart component.
    this.minH = 160;  // the minimum of height of the chart component.
    this.iChartHeight = 80;
	this.xLabelAlign = "left";
	this.yLabelWidth = 50;
    this.showGridLines  = true; 
	
    // the id value of some elements.
    this.autoBoxID;
	 //the jquery object refer to html elements
    this.outObj;   
	
	 // control parameter.
	this.sType = "ST";
    this.mainTicker = mainticker;
	this.iivTicker = "";
    this.compairTickers =[];
	this.tickerInfos = {};
    this.mainTickerInfo = {type:"1",tenforeTicker:""} ;
    this.compairTickerInfo = [];
	this.iivTickerInfo = {};  // for ETF.
	this.events = {dividend:false,splits:false,earnings:false};
    
    this.zoomRange = 1;
    this.chartStyle = "mountain";
    this.showVolume = true;
    this.frequency = "minute";
    this.chartCursor = 1; // 0 Track boll; 1 Crosshair
    this.scaleType = 0; // 0 linear 1: log.
    this.ticksize = 5;
    this.Ticks = null;
    
    this.endDate = new Date();
    this.startDate = this.endDate; // new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate()-5);
    this.ichartSiwtchIndicatorWin = {flag:false,oldName:"",newName:"",data:null,ulelm:null};
	
    //slider control parameters
	this.isShowTimeSlider=true;
    this.pChartReady = false;
    this.sliderObj = null;
    this.slider_EndDate = this.latestTradeDate; //slider end date equal to last trade date.
    this.slider_StartDate = new Date(this.slider_EndDate.getFullYear()-2,this.slider_EndDate.getMonth(),this.slider_EndDate.getDate()) ;
    this.rangSize = 512;  
    this.miniChartFrequency = "minute";
	
     // chart data
	this.chartData ={
		DataList:[],
		VolList:[],
		eventDataList:null,
		eventInfoList:null,
		MiniChartData: [],
		fairValueData:null,
		mReturnIndexData:null
		};
	this.iChartData = {MACD:[],RSI:[],ROC:[],WillR:[],SStochastic:[],FStochastic:[],
		Momentum:[],ULT:[],DMI:[],MFI:[],ULT: [],OBV:[],VAcc:[],UDRatio:[],
		PE:[],PS:[],PB:[],PC:[],RDividend:[],DYield:[],REPS:[],SInterest:[],FVolatility:[],WMA:[],AccDis:[],Mass:[],Volatility:[],ForceIndex:[],ATR:[]};
    // UI system configure
    this.UIConfig = {pCtrl1:{showCompair:true,showTimeRange:true,showFrequency:true,showZoom:true},
		pCtrl2:{showChartType:true,showSMV:true, showEvent:true,showIndicator:true, showCursorType:true},
		vCtrl:{showSMVV:true,showHideLink:true},
		Chart:{showPChart:true,showVChart:true,showLegend:true,showTimeSlider:true},
		RightMenu:true,
		CustomUI:false,
		chartCtrl:"default",
		settingPanel:null,
		fairValue:true,
		autoHeight:false,
		indicator:{},
		valuations:{},
		events:{},
		drawing:{},
		MouseWheel:true,
		ZoomIn:true,
		panel:{showWindow:true, showNote:true},
		IIVLegend:"ticker", //ticker or iNAV.
		onedayDateRangeFormat:1  // 1: date time- date time. 0: date(time-time)
	};
	
    // the flot object parameter.
    this.pFlot = null; // price chart
    this.vFlot = null; // volume chart
    this.mFlot = null; // slider chart.
    this.iFlots = {MACD:null,RSI:null,ROC:null,WillR:null,SStochastic:null,FStochastic:null,
		Momentum:null,ULT:null,DMI:null,MFI:null,ULT: null,OBV:null,
		VAcc:null,UDRatio:null,PE:null,PS:null,PB:null,PC:null,RDividend:null,
		DYield:null,REPS:null,SInterest:null,FVolatility:null,WMA:null,AccDis:null,Mass:null,Volatility:null,ForceIndex:null,ATR:null};
		
    // state parameters	
	this._isIntradayTimSyle  = true;
	this._selectedIndicatorName = ""; // it is for indicator input parameters window.		 
    this.isDrawing = false; // if or not on drawing.
	this.lock = false; // lock
	this.showNotes = false;
    this._indexScrollResized = false;
    this.timeout = null;
	this.mouseWheeTimeout = null;
	this.scrollAble = false;
	this.simpleMenu=false;  // if or not show indicator menu in SR chart right menu.
    this.chartOffset = {left:0,top:0};
	this.hasConfirmBox = (typeof(Util) != "undefined" && typeof(Util.confirm) != "undefined") ? true:false;
	this.yaxisAlign = "right";
	this.isShowLastLabel = true;
	this.showIIVTicker = false;  // for ETF chart.
	this.selectionMode = {pan:true,zoomIn:false,zoomOut:false};
	this.zoomStack = [];
	    // options for legend window
	this.legendInfo = {OHLC:true,Volume:true,onlyIncludeLast:false,showDateRangeString:true};  // OHLC is for Stock, ETF.
	// UI Components
	this.uiComponents = {
		settingGroup:null,           // group menu in setting panel.
		ddlFrequency:null,			 // drop down list for frquency type.
		ddlZoom:null,                // drop down list for zoom type.
		ddlChartType:null,			// drop down list for chart type.
		ddlCursorType:null,         // drop down list for chart cursor.
		customDateB:null,         // customize date boxes.
		tabMenu: null,            // tab panel.
	 	chartTypeMenu: [],        // sub menu for tab menu items.
		tabZoomMenu:null,        // zoom menu in tab panel.
		rightMenu:null,          // right menu for price chart.
		indexScrollPN:null,
		miniChartRightMenu:{}    // right menu for mini-chart (indicator and valuation chart). {menu: menu object,owner:the mini-chart value}
	};
	
	// the jquery object refer to chart component outer element.
	this._contains = {         
		pChartContainer:null,      // for price chart.
		vChartContainer:null,		// for volume chart
		mChartContainer:null,		// for silder chart
		toolContainer : null,      // for right menu.
		$settingPanel : null       // for setting Panel.
	};
	this.iChartContainers = {};    //new chart contains 
	
    this._elements = {
		legendElm:null,
		volLegendElm:null,
		crosshairLegendElm:null,
		crosshairLegendWin:null,
		lineXElm:null,
		lineYElm:null,
		xLabelElm:null,
		addCompairBtElm:null,
		indicatorWinElm:null,
		eventULElm:null,
		valuationULElm:null,
		indexsULElm:null,
		relatedSecULElm:null,
		indicatorULElm:null,
		m1:null,
		m2:null,
		m3:null,
		mv:null,
		volSwitchLink:null,
		chkLock:null,
		growthMenu:null,
		oscIndicatorMenu:null,
		tabmenuZoomEl:null,
		$ddlZoom:null, 
		$ddlFrequency:null, 
		$ddlChartType:null, 
		$ddlCursorType:null,
		$customDate:null,
		$ratioScale:null,
		$drawBlock:null,
		$yaxisAlign:null,
		iivContainer:null,
		zoomMask:null
	}
    this.indicatorUI ={  SMA:{title:QSLGIN.sma_t,parameter:[QSLGIN.sma_p1,QSLGIN.sma_p2,QSLGIN.sma_p3],defaultValue:[10,50,]},
         EMA:{title:QSLGIN.ema_t,parameter:[QSLGIN.ema_p1,QSLGIN.ema_p2,QSLGIN.ema_p3],defaultValue:[10,,]},
         SMAV:{title:QSLGIN.smav_t,parameter:[QSLGIN.smav_p1],defaultValue:[50]},
         BBands:{title:QSLGIN.bbands_t,parameter:[QSLGIN.bbands_p1,QSLGIN.bbands_p2],defaultValue:[20,2]},
         PSAR:{title:QSLGIN.psar_t,parameter:[QSLGIN.psar_p1,QSLGIN.psar_p2],defaultValue:[0.02,0.2]},
         MACD:{title:QSLGIN.macd_t,parameter:[QSLGIN.macd_p1,QSLGIN.macd_p2,QSLGIN.macd_p3],defaultValue:[26,12,9]},
         RSI:{title:QSLGIN.rsi_t,parameter:[QSLGIN.rsi_p1],defaultValue:[14]},
         ROC:{title:QSLGIN.roc_t,parameter:[QSLGIN.roc_p1],defaultValue:[12]},
         WillR:{title:QSLGIN.willr_t,parameter:[QSLGIN.willr_p1],defaultValue:[14]},
         SStochastic:{title:QSLGIN.sstochastic_t,parameter:[QSLGIN.sstochastic_p1,QSLGIN.sstochastic_p2],defaultValue:[15,5]},
         FStochastic:{title:QSLGIN.fstochastic_t,parameter:[QSLGIN.fstochastic_p1,QSLGIN.fstochastic_p2],defaultValue:[5,3]},
         PChannel: {title: QSLGIN.pchannel_t,parameter: [QSLGIN.pchannel_name],defaultValue: [14]},
         MAE: {title: QSLGIN.mae_t,parameter: [QSLGIN.mae_p1, QSLGIN.mae_p2],defaultValue: [14, 2]},
         Momentum:{title:QSLGIN.momentum_t,parameter:[QSLGIN.momentum_p1],defaultValue:[2]},
         ULT: {title:QSLGIN.ult_t,parameter:[],defaultValue: []},
         DMI: {title:QSLGIN.dmi_t,parameter:[],defaultValue:[]},
         MFI: {title: QSLGIN.mfi_t,parameter: [QSLGIN.mfi_p1],defaultValue: [14]},
         OBV: {title:QSLGIN.obv_t,parameter:[],defaultValue:[]},
         VAcc: {title: QSLGIN.vacc_t,parameter: [],defaultValue: []},
         UDRatio: {title:QSLGIN.udratio_t,parameter:[QSLGIN.udratio_p1,QSLGIN.udratio_p2],defaultValue:[7,5]},
         VBP: {title: QSLGIN.vbp_t,parameter: [],defaultValue: []},
         Volume:{title:QSLGIN.volume_t,parameter: [],defaultValue: []},
         VPlus:{title:QSLGIN.vplus_t,parameter: [],defaultValue: []},//jakcy
         FVolatility:{title:QSLGIN.fvolatility_t,parameter: [],defaultValue: []},
         WMA:{title:QSLGIN.wma_t,parameter: [QSLGIN.wma_p1],defaultValue: [15]},
         AccDis:{title:QSLGIN.accdis_t,parameter: [],defaultValue: []},
         Mass:{title:QSLGIN.mass_t,parameter: [],defaultValue: []},
         Volatility:{title:QSLGIN.volatility_t,parameter: [QSLGIN.volatility_p1,QSLGIN.volatility_p2],defaultValue: [10,10]},
         ForceIndex:{title:QSLGIN.forceindex_t,parameter: [QSLGIN.forceindex_p1],defaultValue: [13]},
         ATR:{title:QSLGIN.atr_t,parameter: [],defaultValue: []},
         Keltner:{title:QSLGIN.keltner_t,parameter: [QSLGIN.keltner_p1,QSLGIN.keltner_p2,QSLGIN.keltner_p3],defaultValue: [10,2,20]},
         PrevClose:{title:QSLGIN.prevclose_t,parameter:[],defaultValue:[]}
    };                    
    this.indicatorsData = {SMA:{show:false,num:[null,null,null],colorIndex:[0,0,0],type:0},
        SMAV:{show:false,num:null,colorIndex:0,type:0},
        EMA:{show:false,num:[null,null,null],colorIndex:[0,0,0],type:0},
        BBands:{show:false,parameter:[10,2],colorIndex:0,type:0},
        PSAR:{show:false,parameter:[0.02,0.2],colorIndex:0,type:0},
        MACD:{show:false,parameter:[26,12,9],type:1,mty:1},
        RSI:{show:false,parameter:[14],type:1,mty:2},
        ROC:{show:false,parameter:[12],type:1,mty:1},
        WillR:{show:false,parameter:[14],type:1,mty:2},
        SStochastic:{show:false,parameter:[15,5],type:1,mty:2},
        FStochastic:{show:false,parameter:[5,3],type:1,mty:2},
        PChannel:{show:false,parameter:[14],type:0},
        MAE:{show:false,parameter:[14,2],type:0},
        Momentum:{show:false,parameter:[2],type:1,mty:1},
        ULT: {show:false,parameter: [],type: 1,mty:2},
        DMI: {show:false,parameter: [],type: 1,mty:1},
        MFI: {show:false,parameter: [14],type: 1,mty:0},
        OBV: {show:false,parameter:[],type: 1,mty:0},
        VAcc: {show:false,parameter:[],type: 1,mty:0},
        UDRatio:{show:false,parameter:[7,5],type: 1,mty:0},
        VBP: {show:false,parameter: [],type: 0},
        Volume:{show:true,parameter: [],type: 0,mty:5},
        VPlus:{show:false,parameter: [],type: 0,mty:5},
        FVolatility:{show:false,parameter:[],type: 1},
        WMA:{show:false,parameter:[15],type:0,mty:0},
        AccDis:{show:false,parameter:[],type:1,mty:1},
        Mass:{show:false,parameter:[],type:1,mty:2},
        Volatility:{show:false,parameter:[10,10],type:1,mty:2},
        ForceIndex:{show:false,parameter:[13],type:1,mty:1},
        ATR:{show:false,parameter:[],type:1,mty:1},
        Keltner:{show:false,parameter:[10,2,20],type:0,mty:2},
        PrevClose:{show:false,parameter:[],type:0}
    },
	// maps
	this._securityTypeMap = {"ST":1,"FE":1,"XI":10,"FO":8,"FC":1};
	this._zoomIndexMap = {1:0,2:1,13:2,3:3,14:4,4:5,5:6,6:7,7:8,8:9,9:10,10:11,11:12};
	this._frequencyIndexMap = {minute:-4,minute5:-3,minute10:-2,minute15:-1,minute30:0,d:1,w:2,m:3};
	this._frequencyTxtMap = {minute:"1 "+QSLGTXT.shortminute,minute5:"5 "+QSLGTXT.shortminute,minute10:"10 "+QSLGTXT.shortminute,
		minute15:"15 "+QSLGTXT.shortminute,minute30:"30 "+QSLGTXT.shortminute,d:QSLGTXT.daily,w:QSLGTXT.weekly,m:QSLGTXT.monthly};
	this._frequencyMap={minute:1,minute5:5,minute10:10,minute15:15,minute30:30,d:"d",w:"w",m:"m"};
	this.tabMap =  ["mountain","ohlc","candle","growth"];
	this.tabIndexMap = {"mountain":0,"dot":0,"ab":0,"line":0,"ohlc":1,"hlc":1,"candle":2,"growth":3,"growth10":3,"dEffect":3};
	this.mapValuationName = {HS0A2:"PE",HS0A5:"PS",HS0A0:"PB",HS0A1:"PC",HS987:"FairValue",ST263:"REPS",STA0C:"SInterest"};
	this.indexsMap = {"0P00001G7J": {
			show: false,name:"IXUS:SPX",txt:"S&P 500"
		},"0P00001FJG": {
			show: false,name:"IXUS:$INDU",txt:"DJ Industrial Avg."
		},"0P00001G7B": {
			show: false,name:"IXUS:COMP",txt:"NASDAQ Composite"
		},/*"0P00001LXY": {
			show: false,name:"IXUS:RUT",txt:"Russell 2000"
		},*/
		"0P00001GJH":{
			show:false,name: "IXUS:$MSTAR",txt: "U.S. Market"
	    },"0P00001GJW":{
			show:false,name:"IXUS:$MVAL",txt:"U.S. Value"
	    },"0P00001GJT":{
			show:false,name:"IXUS:$MSVL",txt:"Small Value"          
		},"0P00001GJS":{
			show:false,name:"IXUS:$MMVL",txt:"Mid Value"
	    },"0P00001GJR":{
	        show:false, name:"IXUS:$MLVL",txt:"Large Value"
	    },"0P00001GJV":{
			show:false, name:"IXUS:$MCOR",txt:"U.S. Core"   
	    },"0P00001GJQ": {
			show:false,name:"IXUS:$MSCR",txt:"Small Core"
	    },"0P00001GJP":{
			show:false,name:"IXUS:$MMCR",txt:"Mid Core"
	    },"0P00001GJO":{
			show:false,name:"IXUS:$MLCR",txt:"Large Core"
	    },"0P00001GJU":{
			show:false,name:"IXUS:$MGRO",txt:"U.S. Growth"         
	    },"0P00001GJN":{
			show:false,name:"IXUS:$MSGR",txt:"Small Growth"         
		},"0P00001GJM":{
			show:false,name:"IXUS:$MMGR",txt:"Mid Growth"
	    },"0P00001GJL":{
			show:false,name:"IXUS:$MLGR",txt:"Large Growth"
	    },"0P00001GJK":{
			show:false,name:"IXUS:$MSCP",txt:"U.S. Small Cap"
		},"0P00001GJJ":{
			show:false,name:"IXUS:$MMCP",txt:"U.S. Mid Cap"
	    },"0P00001GJI":{
			show:false,name:"IXUS:$MLCP",txt:"U.S. Large Cap"      
	    },"0P00001N2X":{
			show:false,name:"IXUS:$MDL",txt:"Dividend Leaders"
	    },"0P000083OS":{
			show:false,name:"IXUS:$MWMF",txt:"Wide Moat Focus 20"
	    },"0P000083OP":{
			show:false,name:"IXUS:$MWMO",txt:"Wide Moat 100"
	    },"0P00001MJQ":{
			show:false,name:"IXUS:$INFOS",txt:"Information Sup. Sector"
	    },"0P00001MJS":{
			show:false,name:"IXUS:$MFGRS",txt:"Manufacturing Sup. Sector"
	    },"0P00001MJR":{
			show:false,name:"IXUS:$SRVCS",txt:"Service Sup. Sector"
	    },"0P00001G7I":{
			show:false,name:"IXUS:MID",txt:"S&P MidCap 400"
	    },/*"0P00006F5U": {
			show:false,name:"XBRU:BEL20",txt:"Euronext BEL 20 (BEL)"
	    },"0P00008ICX": {
			show:false,name:"XPAR:PX1",txt:"Euronext Paris CAC 40 (FRA)"
	    },*/"0P00001IS1": {
			show:false,name:"XLON:UKX",txt:"FTSE 100 (GBR)"
		}/*,"0P00001IS2": {
			show:false,name:"XLON:MCX",txt:"FTSE 250 (GBR)"
	    },"0P00006G3M": {
			show:false,name:"XETR:DAX",txt:"FSE DAX (DEU)"         
	    }, "0P00006MR4":{
			show:false,name:"XOSE:NI225",txt:"Nikkei 225 (JPN)"
	 	}*/,"0P00006NNM":{
			show:false,name:"XSHG:$000001",txt:"Shanghai SE Composite (CHN)"
	    },"0P00008IVF": {
			show:false,name:"XTSE:OSPTX",txt:"S&P\/TSX Composite (CAN)"
	    }
	};
	// data list for UI control components.
//	this.drawingData =[{val:"trendline",txt:"Trend Line"},{val:"rectangle",txt:"Rectangle"},
//		{val:"ellipse",txt:"Ellipse"},{val:"note",txt:"Note"},{val:"levelline",txt:"Level Line"},{val:"fibonacci",txt:"Fibonacci Retracement Levels"}];
	 // indicators parameters

    this.valuations = {PE:{show:false,code:"HS0A2",colorIndex:0,name:QSLGFD.pe_name,mty:4},
		PS:{show:false,code:"HS0A5",colorIndex:0,name:QSLGFD.ps_name,mty:4},
		PB:{show:false,code:"HS0A0",colorIndex:0,name:QSLGFD.pb_name,mty:4},
		PC:{show:false,code:"HS0A1",colorIndex:0,name:QSLGFD.pc_name,mty:4},
		FairValue:{show:false,code:"HS987",colorIndex:0,name:QSLGFD.fairvalue_name},
		RDividend:{show:false,code:"",colorIndex:0,name:QSLGFD.rdividend_name,mty:3},
		DYield:{show:false,code:"",colorIndex:0,name:QSLGFD.dyield_name,mty:3},
		REPS:{show:false,code:"ST263",colorIndex:0,name:QSLGFD.reps_name,mty:3},
		SInterest:{show:false,code:"STA0C",colorIndex:0,name:QSLGFD.sinterest_name,mty:3}
   	};
   	this.intradayFreMenuData = [{txt:"1 "+QSLGTXT.shortminute,val:"minute",type: "ratio"},{txt:"5 "+QSLGTXT.shortminute,val:"minute5",type: "ratio"},
		{txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},{txt:"15 "+QSLGTXT.shortminute,val:"minute15",type: "ratio"},
		{txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"}];
	this.sMinuteFreMenuData=[{txt:"5 "+QSLGTXT.shortminute,val:"minute5",type: "ratio"},{txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},
		{txt:"15 "+QSLGTXT.shortminute,val:"minute15",type: "ratio"},{txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"},
		{txt:QSLGTXT.daily,val:"d",type: "ratio"}];
	this.lMinuteFreMenuData=[{txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},{txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"},
		{txt:QSLGTXT.daily,val:"d",type: "ratio"},{txt:QSLGTXT.weekly,val:"w",type: "ratio"}];
	this.dailyFreMenuData=[{txt:QSLGTXT.daily,val:"d",type: "ratio"},{txt:QSLGTXT.weekly,val:"w",type: "ratio"},
		{txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
	this.weeklyFreMenuData=[{txt:QSLGTXT.weekly,val:"w",type: "ratio"},{txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
	this.monthlyFreMenuData = [{txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
	this.eventsData = [{
        txt: QSLGTXT.dividend,
        val: "dividend",
        name: "dividends",
        type: "checkbox",
        checked: false
    }, {
        txt: QSLGTXT.splits,
        val: "splits",
        name: "splits",
        type: "checkbox",
        checked: false
    }, {
        txt: QSLGTXT.earnings,
        val: "earnings",
        name: "earnings",
        type: "checkbox",
        checked: false
    }];
	
    this.zoomListData =  [{txt:"1 "+QSLGTXT.shortday,val:"1",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.intradayFreMenuData},
		{txt:"5 "+QSLGTXT.shortday,val:"2",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.intradayFreMenuData},
		{txt:"15 "+QSLGTXT.shortday,val:"13",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.sMinuteFreMenuData},
		{txt:"1 "+QSLGTXT.shortmonth,val:"3",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.sMinuteFreMenuData},
		{txt:"2 "+QSLGTXT.shortmonth,val:"14",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.lMinuteFreMenuData},
		{txt:"3 "+QSLGTXT.shortmonth,val:"4",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.lMinuteFreMenuData},
        {txt:QSLGTXT.ytd,val:"5",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"1 "+QSLGTXT.shortyear,val:"6",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"3 "+QSLGTXT.shortyear,val:"7",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"5 "+QSLGTXT.shortyear,val:"8",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"10 "+QSLGTXT.shortyear,val:"9",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:QSLGTXT.max,val:"10",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.monthlyFreMenuData},
		{txt:QSLGTXT.custom,val:"11",type: "ratio"}];
    this.frequencyListData = [{txt:"1 "+QSLGTXT.shortminute,val:"minute"},{txt:"5 "+QSLGTXT.shortminute,val:"minute5"},
		{txt:"10 "+QSLGTXT.shortminute,val:"minute10"},{txt:"15 "+QSLGTXT.shortminute,val:"minute15"},
		{txt:"30 "+QSLGTXT.shortminute,val:"minute30"},
		{txt:QSLGTXT.daily,val:"d"},{txt:QSLGTXT.weekly,val:"w"},{txt:QSLGTXT.monthly,val:"m"}];
    this.cursorTypeListData = [{txt:QSLGTXT.trackball,val:"0",type: "ratio"},{txt:QSLGTXT.crosshair,val:"1",type: "ratio"},
       {txt:QSLGTXT.off,val:"3",type: "ratio"}];
	this.chartTypeListData = [{txt:QSLGTXT.mountain,val:"mountain",type: "ratio"},{txt:QSLGTXT.line,val:"line",type: "ratio"},
		{txt:QSLGTXT.dot,val:"dot",type: "ratio"},{txt:QSLGTXT.abovebelow,val:"ab",type: "ratio"},{txt:QSLGTXT.ohlc,val:"ohlc",type: "ratio"},
		{txt:QSLGTXT.hlc,val:"hlc",type: "ratio"},{txt:QSLGTXT.candlestick,val:"candle",type: "ratio"},
		{txt:QSLGTXT.pergrowth,val:"growth",type: "ratio"},{txt:QSLGTXT.tenkgrowth,val:"growth10",type: "ratio"},
		{txt:QSLGTXT.dividendeffect,val:"dEffect",type: "ratio"}];
	this.scaleTypeListData = [{txt:QSLGTXT.linear,val:"0"},{txt: QSLGTXT.logarithmic,val:"1"}];
	this.yaxisAlignListData=[{txt: QSLGTXT.left,val:"left"},{txt:QSLGTXT.right,val:"right"}];
	this.selectionModeListData=[{txt: QSLGTXT.pan,val:"pan"},{txt: QSLGTXT.zoomin,val:"zoomin"},{txt: QSLGTXT.reset,val:"reset"}];
	this.tabList=[{txt:QSLGTXT.line,id:0,closable:false},
		{txt:QSLGTXT.bar,id:1,closable:false},{txt:QSLGTXT.candlestick,id:2,closable:false},
		{txt:QSLGTXT.growth,id:3,closable:false}];
	/*this.growthMenuData = [{txt:"% Growth",type:"ratio",val:"growth"},
		{txt:"10K Growth",type:"ratio",val:"growth10"},
		{txt:"Dividend Effect",type:"ratio",val:"dEffect"}];*/
	this.chartTypeMenuData=[[{txt:QSLGTXT.mountain,type:"ratio",val:"mountain"},
		{txt:QSLGTXT.line,type:"ratio",val:"line"},{txt:QSLGTXT.dot,type:"ratio",val:"dot"},{txt:QSLGTXT.abovebelow,type:"ratio",val:"ab"}],
		[{txt:QSLGTXT.ohlc,type:"ratio",val:"ohlc"},{txt:QSLGTXT.hlc,type:"ratio",val:"hlc"}],[],[{txt:QSLGTXT.pergrowth,type:"ratio",val:"growth"},
		{txt:QSLGTXT.tenkgrowth,type:"ratio",val:"growth10"},{txt:QSLGTXT.dividendeffect,type:"ratio",val:"dEffect"}]];
	this.settingGroupList = [{name: QSLGTXT.display,id: 1},{name: QSLGTXT.window,id: 7}, {name: QSLGTXT.compare,id: 2,closable: false},
	 	{name: QSLGTXT.drawingandnotes,id: 3},{name: QSLGTXT.indicators,id: 4},
		{name: QSLGTXT.events,id: 5},{name: QSLGTXT.fundamental,id: 6}];
	this.indicatorTabList=[{txt:QSLGTXT.popular,id:0,closable:false},{txt:QSLGTXT.cvolume,id:1,closable:false},
		{txt:QSLGTXT.pricetrends,id:2,closable:false},{txt:QSLGTXT.oscillator,id:3,closable:false}];
	this.indicatorPanelData=[[{txt:QSLGIN.bbands_name,val:"BBands",type: ""},{txt:QSLGIN.macd_name,val:"MACD",type: ""},
		{txt:QSLGIN.psar_name,val:"PSAR",type: ""},{txt:QSLGIN.prevclose_name,val:"PrevClose",type: ""},
		{txt:QSLGIN.roc_name,val:"ROC",type: ""},
		{txt:QSLGIN.rsi_name,val:"RSI",type: ""},{txt: QSLGIN.sma_name,val: "SMA",type: ""},
		{txt:QSLGIN.sstochastic_name,val:"SStochastic",type: ""},{txt:QSLGIN.fstochastic_name,val:"FStochastic",type: ""},
		{txt:QSLGIN.willr_name,val:"WillR",type: ""}],
		[{txt: QSLGIN.mfi_name,val: "MFI",type: ""},{txt: QSLGIN.obv_name,val: "OBV",type: ""},
		 {txt: QSLGIN.udratio_name,val: "UDRatio",type: ""},{txt: QSLGIN.volume_name,val: "Volume",type: ""},
		 {txt: QSLGIN.vplus_name,val: "VPlus",type: ""},
		 {txt: QSLGIN.vacc_name,val: "VAcc",type: ""},{txt: QSLGIN.vbp_name,val: "VBP",type: ""},
		 {txt: QSLGIN.smav_name,val: "SMAV",type: ""},{txt: QSLGIN.accdis_name,val: "AccDis",type: ""}],
		[{txt:QSLGIN.bbands_name,val:"BBands",type: ""},{txt:QSLGIN.dmi_name,val:"DMI",type: ""},{txt:QSLGIN.ema_name,val:"EMA",type: ""},
		 {txt:QSLGIN.mae_name,val:"MAE",type: ""},{txt:QSLGIN.macd_name,val:"MACD",type: ""},
		 {txt:QSLGIN.momentum_name,val:"Momentum",type: ""},{txt:QSLGIN.psar_name,val:"PSAR",type: ""},
		 {txt:QSLGIN.pchannel_name,val:"PChannel",type: ""},{txt:QSLGIN.prevclose_name,val:"PrevClose",type: ""},
		 {txt:QSLGIN.roc_name,val:"ROC",type: ""},
		  {txt:QSLGIN.sma_name,val: "SMA",type: ""},{txt: QSLGIN.wma_name,val: "WMA",type: ""},
		  {txt: QSLGIN.forceindex_name,val: "ForceIndex",type: ""},{txt: QSLGIN.atr_name,val: "ATR",type: ""}],//,{txt: "Volatility-Fast",val: "FVolatility"}
		[{txt:QSLGIN.rsi_name,val:"RSI",type: ""},{txt:QSLGIN.sstochastic_name,val:"SStochastic",type: ""},
		  {txt:QSLGIN.fstochastic_name,val:"FStochastic",type: ""},
		 {txt:QSLGIN.ult_name,val:"ULT",type: ""},{txt:QSLGIN.willr_name,val:"WillR",type: ""},{txt:QSLGIN.mass_name,val:"Mass",type: ""},
		{txt:QSLGIN.volatility_name,val:"Volatility",type: ""},{txt: QSLGIN.keltner_name,val: "Keltner",type: ""}]
	 	];   
	this.fundamentalTabList = [{txt:QSLGTXT.fundamental,id:0,closable:false},{txt:QSLGTXT.valuation,id:1,closable:false}];
	this.fundamentalPanelData = [[{txt: QSLGFD.rdividend_name,val: "RDividend"},{txt: QSLGFD.dyield_name,val: "DYield"},
		{txt: QSLGFD.reps_name,val: "REPS"},{txt: QSLGFD.sinterest_name,val: "SInterest"}],
	    [{txt:QSLGFD.pe_name,val:"PE"},{txt:QSLGFD.ps_name,val:"PS"},{txt:QSLGFD.pb_name,val:"PB"},
		{txt:QSLGFD.pc_name,val:"PC"},{txt:QSLGFD.fairvalue_name,val:"FairValue"}]];
	this.ichartMenuData = [[{txt:QSLGTXT.cvolume,val:"Volume"},
		{txt: QSLGIN.vplus_name,val:"VPlus"}]];
	 //min-chart right menu list data.
    this.indicatorL2Data=[{txt:QSLGTXT.cvolume,val:"mainl2-volume",selectable: false,subMenu:this.indicatorPanelData[1]},
		{txt:QSLGTXT.pricetrends,selectable: false,val:"mainl2-pricetrend",subMenu:this.indicatorPanelData[2]},
		{txt:QSLGTXT.oscillator,val:"mainl2-oscillator",selectable: false,subMenu:this.indicatorPanelData[3]}];
	this.ichartMenuL1Data=[[],[],[],[],[]]; //min-chart right menu list data. one class.
    this.miniChartRightMenuData = [{
	        txt: "<b>"+QSLGTXT.indicators+"</b>",
	        val: "mini-indicator",
	        selectable: false
	    }, {
	        txt: "&nbsp;&nbsp;"+QSLGTXT.cvolume,
	        val: "minil1-volume",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        txt: "&nbsp;&nbsp;"+QSLGTXT.pricetrends,
	        val: "minil1-pricetrend",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        txt: "&nbsp;&nbsp;"+QSLGTXT.oscillator,
	        val: "minil1-oscillator",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        txt: QSLGTXT.fundamental,
	        val: "minil1-fundamental",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        txt: QSLGTXT.valuation,
	        val: "minil1-valuation",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        type: 'separator',
	        val: "s2"
	    }, {
	        txt: QSLGTXT.edit,
	        val: "edit"
	    }];
    this.rightMenuData = [{
	        txt: QSLGTXT.charttype,
	        val: "chartType",
	        type: "",
	        selectable: false,
	        subMenu: this.chartTypeListData
	    }, {
	        txt: QSLGTXT.chartcursor,
	        val: "cursorType",
	        type: "",
	        selectable: false,
	        subMenu: this.cursorTypeListData
	    }, {
	        txt: QSLGTXT.zoom,
	        val: "zoom",
	        type: "",
	        selectable: false,
	        subMenu: this.zoomListData
	    }, {
	        txt: QSLGTXT.events,
	        type: "",
	        val: "event",
	        selectable: false,
	        subMenu: this.eventsData
	    }, {
	        txt: QSLGTXT.indicators,
	        val: "indicator",
	        selectable: false,
	        subMenu: this.indicatorL2Data
	    }, {
	        txt: QSLGTXT.fundamental,
	        val: "mainl1-fundamental",
	        selectable: false,
	        subMenu: this.fundamentalPanelData[0]
	    }, {
	        txt: QSLGTXT.valuation,
	        val: "mainl1-valuation",
	        selectable: false,
	        subMenu: this.fundamentalPanelData[1]
	    }];
};
RTChartComponent.prototype = $.extend({},QS_baseChart,{
	// initilize chart interfaces.
	initUIConfig:function(config) { // init the chart UI configuration.
        $.extend(this.UIConfig,config);
		/*for(var i in this.indicatorUI){
			if(!this.extendConfig.indicators.hasOwnProperty(i)){
				delete this.indicatorUI[i];
				delete this.indicatorsData[i];
			}
		}*/
		this._checkPermission();  // check permission.
        if (this.UIConfig.settingPanel != null) {
            this._contains.$settingPanel = $(this.UIConfig.settingPanel);
        }    
    },
	Init:function(outID,objname,config) {  // init remove the objname parameter.
        ///this.objName = objname;
		if(typeof(this.id)=="undefined") {
			this.id = outID;
			if(typeof(GB_ChartDataManager)=="object") GB_ChartDataManager.subscribeChart(this);
		}
        this.outObj = $("#"+outID).addClass("rtc-chart-out");
        this.autoBoxID = outID+"_autoBox";
        this.createChartUI();                      // create UI elements.
        this._initConfig(config);                  // init the user's configuration (chart state)
        this._createUiComponents();              // create Ui Components for chart.
		var t = [];
		if (typeof(this.mainTicker) != "undefined" && this.mainTicker != null && this.mainTicker != "") {
			t.push(this.mainTicker);
		}
		if(this.compairTickers && this.compairTickers.length > 0){
			t = t.concat(this.compairTickers);
		}
		if(t.length > 0){
			this.validateSavedTickers(t);
		}
    },
	_checkPermission:function(){  // remove some ui item according to permission.
		var uc = this.UIConfig;
		for(var i = 0;i<this.indicatorPanelData.length;i++){
			var k = this.indicatorPanelData[i];
			for(var j = 0;j<k.length;j++){
				if(typeof(uc.indicator[k[j].val])!="undefined"&&!uc.indicator[k[j].val]){
					k.splice(j,1);
					j--;
				}
			}
		}
		for(var i = 0;i<this.fundamentalPanelData.length;i++){
			var k = this.fundamentalPanelData[i];
			for(var j = 0;j<k.length;j++){
				if(typeof(uc.valuations[k[j].val])!="undefined"&&!uc.valuations[k[j].val]){
					delete this.valuations[k[j].val];
					k.splice(j,1);
					j--;
				}
			}
		}
		for(var i = 0;i<this.drawingData.length;i++){
			if(typeof(uc.drawing[this.drawingData[i].val])!="undefined"&&!uc.drawing[this.drawingData[i].val]){
				drawingData.splice(i,1);
				i--;
			}
		}
		for(var i = 0;i<this.eventsData.length;i++){
			if(typeof(uc.events[this.eventsData[i].val])!="undefined"&&!uc.events[this.eventsData[i].val]){
				this.eventsData.splice(i,1);
				i--;
			}
		}
	}, 
	
	// save and initilize configuration.
	_initConfig: function(cf)  { // init the chart's configuration
        if (cf == null || cf == "") {
            return;
        }
		if(cf.simpleMenu){  // if minichart for SR components.
			this.simpleMenu = true;
			this.rightMenuData.splice(4,3);
		}
		if (cf.chartStyle!=null){ 
			this.chartStyle = cf.chartStyle=="lines"?"mountain":cf.chartStyle;
            var hasStyle = false;
            for(var i = 0;i< this.chartTypeListData.length;i++){  //fix bug #1202 - david
                if(this.chartTypeListData[i].val == this.chartStyle){
                    hasStyle = true;
                    break;
                }
            }
			if(!hasStyle){
				this.chartStyle="mountain";
			}
		}
		if(cf.autoTitle!=null)this.autoTitle = cf.autoTitle;
		if (cf.title)this._title = cf.title;
		if(cf.requencyMenuCfg){
			this.requencyMenuCfg=cf.requencyMenuCfg;
		}
        if (cf.mTicker != null) this.mainTicker = cf.mTicker; 
		if (cf.cTickers != null) this.compairTickers = cf.cTickers;
        if (cf.pWidth != null) this.chartWidth=cf.pWidth; 
        if (cf.pHeight != null) this.pChartHeight=cf.pHeight; //if (cf.vHeight != null) vChartHeight = cf.vHeight;
        if (cf.zRange != null) this.zoomRange = cf.zRange; 
		if (cf.startDate != null) this.startDate = RTQ_ChartUtil.convertToDate(cf.startDate);
        if (cf.endDate != null) this.endDate = RTQ_ChartUtil.convertToDate(cf.endDate);
		if (cf.region != null) this.region = cf.region;
        if (cf.lan != null) this.lan = cf.lan; 
		if (cf.cur != null) this.cur = cf.cur;
        if (cf.frequency != null) this.frequency = cf.frequency; 
        if (cf.slider_StartDate != null) this.slider_StartDate = RTQ_ChartUtil.convertToDate(cf.slider_StartDate);
        if (cf.miniChartFrequency != null) this.miniChartFrequency = cf.miniChartFrequency; 
	 	if (cf.isD != null) this.events.dividend = cf.isD;
		if (cf.isS != null)this.events.splits = cf.isS;
		if (cf.isEarnings) this.events.earnings = cf.isEarnings;
		if (cf.events != null)$.extend(true,this.events,cf.events);
        if (cf.showVolume != null) this.showVolume = cf.showVolume;
        if (cf.tickerInfos) this.tickerInfos = cf.tickerInfos;
        if (cf.chartCursor != null) this.chartCursor = cf.chartCursor;
		if (cf.lock!=null)this.lock = cf.lock;
		if (cf.showNotes!=null)this.showNotes = cf.showNotes;
		if (cf.showIIVTicker!=null)this.showIIVTicker = cf.showIIVTicker;
		if(cf.yaxisAlign!=null){this.yaxisAlign=cf.yaxisAlign};
		if(cf.isShowTimeSlider!=null)this.isShowTimeSlider = cf.isShowTimeSlider;
        if (cf.indicatorsData){  // change  the old stucture.
        	$.extend(true,this.indicatorsData,cf.indicatorsData);
			for(var o in this.indicatorsData){
				if(this.indicatorsData[o].hasOwnProperty("oFlot"))delete this.indicatorsData[o]["oFlot"];
			}
		}
	    if (cf.indicatorVisiable != null) {  // convert the old config  to new.
			for(var o in cf.indicatorVisiable){
				if(cf.indicatorVisiable[o]){
					this.indicatorsData[o].show = true;
				}
			}
		}
		if(cf.valuations)$.extend(true,this.valuations,cf.valuations);
		if(cf.scaleType)this.scaleType = cf.scaleType;
		if(cf.ticksize)this.ticksize = cf.ticksize;
		if(cf.Ticks)this.Ticks = cf.Ticks;
		// change the stored old data formate to new;
		if(!cf.smvV && !this.indicatorsData["SMAV"]){
			this.indicatorsData["SMAV"] = {show:false,num:null,colorIndex:0,type:0};
		}else if(!this.indicatorsData["SMAV"]){
			this.indicatorsData["SMAV"] = {show:true,num:cf.smvV,colorIndex:0,type:0};
		}
		if((!cf.smvP || !cf.smvP.length) && !this.indicatorsData["SMA"]){
			this.indicatorsData["SMA"] = {show:false,num:[null,null,null],startPos:[null,null,null],colorIndex:[0,0,0],type:0};
		}else if(cf.smvP && cf.smvP.length){
			this.indicatorsData["SMA"] = {show:true,num:[cf.smvP[0]?cf.smvP[0]:null,cf.smvP[1]?cf.smvP[1]:null,
				cf.smvP[2]?cf.smvP[2]:null],colorIndex:[0,0,0],type:0};
		}
		if(this.indicatorsData.EMA.length){   // old structure;
			var ema  = {show:false,num:[null,null,null],colorIndex:[0,0,0],type:0};
			for(var i=0; i< this.indicatorsData.EMA.length;i++){
				ema.num[i]= this.indicatorsData.EMA[i].num;
				ema.colorIndex[i]= this.indicatorsData.EMA[i].colorIndex;
			}
			this.indicatorsData.EMA = ema;
		}
		if(this.UIConfig.chartCtrl=="default"){
			/*var smaNums  = this.indicatorsData["SMA"]["num"];
			if(smaNums&&typeof(m1)!="undefined"){
				smaNums[0]== null?"":m1.val(smaNums[0]);
				smaNums[1]== null?"":m2.val(smaNums[1]);
				smaNums[2]== null?"":m3.val(smaNums[2]);
			}
			this.indicatorsData["SMAV"]["num"]==null?"":mv.val(this.indicatorsData["SMAV"]["num"]);*/
		}
        if (cf.width != null) {
            this.chartWidth = (cf.width>this.minW)?cf.width:this.minW; 
        }
        if (cf.height != null) {
			if (this.UIConfig.chartCtrl == "rtqPanel") {
				this.outHeight = cf.height - 26;//window title=26 reduce window title.
			}else {
				this.outHeight = cf.height;
			}
			this._setSizeParas(this.chartWidth,this.outHeight);
			if(this.showVolume){
				this._elements.volLegendElm.show();
			}else{
				if(this._elements.volLegendElm!=null)this._elements.volLegendElm.hide();
			}	
        } 
		this.outObj.css({width:this.chartWidth+"px",height:this.outHeight+"px"});
        this._contains.pChartContainer.css({width:this.chartWidth+"px",height:this.pChartHeight+"px"});
		if(this._elements.zoomMask!=null)this._elements.zoomMask.css({height:this.pChartHeight+"px"});
        if(this._contains.vChartContainer!=null)this._contains.vChartContainer.css({width:this.chartWidth+"px",height:this.vChartHeight+"px"});
        if(this._contains.mChartContainer!=null)this._contains.mChartContainer.css({width:this.chartWidth+"px",height:this.miniChartHeight+"px"});
    },
	saveConfig: function() {  // save the chart's configuration.
        var cf = {title:this._title,autoTitle:this.autoTitle,mTicker:this.mainTicker,cTickers:this.compairTickers,pWidth:this.chartWidth,pHeight:this.pChartHeight,
        vHeight:this.vChartHeight,mHeight:this.miniChartHeight,events:this.events,
		zRange:this.zoomRange,startDate:RTQ_ChartUtil.formatDate(this.startDate),
        endDate:RTQ_ChartUtil.formatDate(this.endDate),region:this.region,lan:this.lan,cur:this.cur,frequency:this.frequency, 
        slider_StartDate:RTQ_ChartUtil.formatDate(this.slider_StartDate),
        miniChartFrequency:this.miniChartFrequency,chartStyle:this.chartStyle,showVolume:this.showVolume,
        tickerInfos:this.tickerInfos,chartCursor:this.chartCursor,scaleType:this.scaleType,yaxisAlign:this.yaxisAlign,
        ticksize:this.ticksize,Ticks:this.Ticks,lock:this.lock,showNotes:this.showNotes,showIIVTicker:this.showIIVTicker,isShowTimeSlider:this.isShowTimeSlider,requencyMenuCfg:this.requencyMenuCfg};
		var inds = {},vals={},indD = this.indicatorsData;
		for(var o in indD){
			if(indD[o].show||(!indD[o].show && o=="Volume")){ // volume: default value is true.
				if(o == "SMA"||o == "SMAV"||o == "EMA"){
					inds[o]= {show:true,num:typeof(indD[o].num)=="object"?$.extend(true,[],indD[o].num):indD[o].num};
				}else{
					inds[o]= {show:indD[o].show,parameter:$.extend(true,[],indD[o].parameter)};
				}
			}
		}
		for(var o in this.valuations){
			if(this.valuations[o].show){
				vals[o]= {show:true};
			}
		}
		cf.indicatorsData=inds;
		cf.valuations=vals;
		return cf;
	},
	 _initUiComponentsStatus: function() {  // initilize the status of UI  components.
	 	var el = this._elements, uiComps = this.uiComponents;
        if(uiComps.ddlZoom != null) uiComps.ddlZoom.setDisable(false);
        if(uiComps.ddlChartType != null) uiComps.ddlChartType.setDisable(false);
        if(uiComps.ddlCursorType!= null) uiComps.ddlCursorType.setDisable(false);
        if(uiComps.ddlFrequency != null) uiComps.ddlFrequency.setDisable(false);
		if(uiComps.settingPlugin!=null)uiComps.settingPlugin.setName(this.autoTitle,this.autoTitle?"":this._title);
        if (uiComps.rightMenu != null) {
            if(this.events.dividend) uiComps.rightMenu.changeUIState("dividend",null,true);
            if(this.events.splits) uiComps.rightMenu.changeUIState("splits",null,true);
			if(this.events.earnings) uiComps.rightMenu.changeUIState("earnings",null,true);
			uiComps.rightMenu.changeUIState(this.chartStyle,null,true);
			uiComps.rightMenu.changeUIState(this.chartCursor,null,true);
        }
        if (this.UIConfig.chartCtrl == "default"&&el.volSwitchLink!=null&&typeof(el.volSwitchLink)!="undefined"){
			el.volSwitchLink.html((this.showVolume?QSLGTXT.hide:QSLGTXT.show));
		} 
        if(this.chartCursor != "1" && this.chartCursor != 1) {
            el.lineXElm.hide();
            el.lineYElm.hide();
        }
		if(this.isShowTimeSlider && uiComps.chkLock!=null){
			uiComps.chkLock.btns["showTimeSlider"].select();
		}
		if(this.showNotes && uiComps.chkLock!=null){
			uiComps.chkLock.btns["showNotes"].select();
		}
		if(this.lock == true && uiComps.chkLock!=null){
			uiComps.chkLock.btns['lock'].select();
		}
		if(this.showIIVTicker && uiComps.chkIIV != null){
			uiComps.chkIIV.btns['showIIV'].select();
		}
		if(this.yaxisAlign=="right"){
			if(el.$yaxisAlign){
				el.$yaxisAlign.find("[value='left']").addClass("rtq-ratio-off");
				el.$yaxisAlign.find("[value='right']").removeClass("rtq-ratio-off");
			}
			el.xLabelElm.css({right:0,left:""});
		}else{
			if (el.$yaxisAlign) {
				el.$yaxisAlign.find("[value='right']").addClass("rtq-ratio-off");
				el.$yaxisAlign.find("[value='left']").removeClass("rtq-ratio-off");
			}
			el.xLabelElm.css({left:0,right:""});
		}
        if (uiComps.ddlZoom != null) {
			uiComps.ddlZoom.setTextValue(null, this.zoomRange);
		}
        if (uiComps.ddlFrequency != null) uiComps.ddlFrequency.setTextValue(null,this.frequency);
        if (uiComps.ddlCursorType != null) uiComps.ddlCursorType.setTextValue(null,this.chartCursor);
        if (uiComps.ddlChartType != null) uiComps.ddlChartType.setTextValue(null,this.chartStyle);
		if(this.scaleType == 1){  // change scale ratio state. 
			el.$ratioScale.find("[value='0']").addClass("rtq-ratio-off");
			el.$ratioScale.find("[value='1']").removeClass("rtq-ratio-off");
		}
		if (uiComps.tabMenu != null){
			var ing = this.tabIndexMap[this.chartStyle];
			uiComps.tabMenu.changeTabByIndex(ing,false);
		}
		for(var i = 0;i<this.chartTypeMenuData.length;i++){
			if(uiComps.chartTypeMenu[i]!=null && this.tabIndexMap[this.chartStyle]==i){  // select tab is growth.
				uiComps.chartTypeMenu[i].changeUIState(this.chartStyle,null,true);
			}
		}
        var obj = (this.UIConfig.chartCtrl == "default") ? this.outObj: el.eventULElm;
        if(this.events.dividend) obj.find("a[value='dividend']").removeClass("rtq-chkbox_off");
        if(this.events.splits) obj.find("a[value='splits']").removeClass("rtq-chkbox_off");
		if(this.events.earnings) obj.find("a[value='earnings']").removeClass("rtq-chkbox_off");
        for (var o in this.indicatorsData) {             // change indicator menu state.
            if (this.indicatorsData.hasOwnProperty(o) ) {
                 if (this.indicatorsData[o].show) {
                      el.indicatorULElm.find("a[value='"+o+"']").removeClass("rtq-chkbox_off");
                      if (this.UIConfig.RightMenu) {
                          if (o == "Volume") {
                              this.changeRightMenuClass(2, o, this.showVolume);
                              continue;
                          }
                          this.changeRightMenuClass(2, o, true);
                      }
                 }
            }
        }
		for(var o in this.valuations){
			if(this.valuations[o].show){
				el.valuationULElm.find("a[value='"+o+"']").removeClass("rtq-chkbox_off");
				if(this.UIConfig.RightMenu && this.valuations[o].hasOwnProperty("mty")){
					this.changeRightMenuClass(2, o, true);
				}else if(o=="FairValue"){
					this.changeRightMenuClass(2, o, true);
				}
			}
		}
		for(var i=0;i<this.compairTickers.length;i++){
			if(this.indexsMap[this.compairTickers[i]]){
				this.indexsMap[this.compairTickers[i]].show = true;
				el.indexsULElm.find("a[value='"+this.compairTickers[i]+"']").removeClass("rtq-chkbox_off");
			}
		}
    },
	
	// generate UI elements and UI components.
	createChartUI:function() {
		var self = this,uc = this.UIConfig, el = this._elements, cons = this._contains,uiComps = this.uiComponents;
        uiComps.ddlChartType = uiComps.ddlFrequency = uiComps.ddlZoom = uiComps.ddlCursorType = null;	
        if (!uc.CustomUI) this.outObj.html(""); // clear html.
        if (uc.chartCtrl == "default" && uc.pCtrl1 && uc.pCtrl1 != null ) {
            var p1 = $('<div class="rtc-ctrl1"></div>');
            if (uc.pCtrl1.showCompair) p1.append('<span class="rtc-ctrl-lb1B" style="padding-left: 5px">'+QSLGTXT.compare+'</span>'+
			'<input id ="'+this.autoBoxID+'" class="qs-ui-ipt" type="text" style="width: 90px;" value="" />'+
			'<a href="javascript:void(0)" class="qs-ui-btn go qs-compare-button">ADD</a>');
            if (uc.pCtrl1.showTimeRange) p1.append('<div class="rtc-ctrl-sect customRange"></div> ');
            if (uc.pCtrl1.showFrequency) p1.append('<div class="rtc-ctrl-sect ddlFrequency"></div>');
            if (uc.pCtrl1.showZoom) {
                p1.append('<div class="rtc-ctrl-sect ddlZoom"></div>');
            }
			el.addCompairBtElm = p1.find(".qs-compare-button");
            this.outObj.append(p1);
            p1 = null;
        }
        if (uc.chartCtrl == "default" && uc.pCtrl2 && uc.pCtrl2 != null) { 
			this.outObj.addClass("qs-default-chart");
            var p2 = $('<div class="rtc-ctrl2"></div>');
            if (uc.pCtrl2.showChartType) p2.append('<div class="rtc-ctrl-sect ddlChartType" style="padding-left: 0"> </div>');
            if (uc.pCtrl2.showSMV) {
				var vStr = '<div class="rtc-ctrl-sect"><span class="rtc-ctrl-lb2B">'+QSLGTXT.movavg+'</span>';
				for(var i = 0; i<3;i++){
					vStr+='<input type="text" style="width: 40px;" class="qs-ui-ipt qs-mov'+(i+1)+'" />';
				}
				p2.append(vStr);
			}
            if (uc.pCtrl2.showEvent) {
				var eStr = '<div class="rtc-ctrl-sect"><li class="rtc-pmdd1" style="height: 26px">';
				eStr+='<a class="rtc-pmddh1" href="javascript:void(0)">'+QSLGTXT.events+'</a><ul class = "qs-event-list">';
				for(var o in this.eventsData){
					var eo = this.eventsData[o];
					eStr += '<li><a href="javascript:void(0)" class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off" ';
					eStr +=' value="'+eo.val+'" catkey="event">'+eo.txt+'</a></li>';
				}
				eStr+='</ul></li></div>';
				p2.append(eStr);
			}
            if (uc.pCtrl2.showIndicator){
				var iStr = '<div class="rtc-ctrl-sect"> <li class="rtc-pmdd1 rtc-menu-trigger" style="height: 26px;width:120px">';
				iStr += '<a class="rtc-pmddh1" href="javascript:void(0)">'+QSLGTXT.indicators+'</a><ul class="qs-indicator-list">';
				for (var o=0; o<this.indicatorPanelData[0].length;o++) {// popular indicators. 
					var io = this.indicatorPanelData[0][o];
					iStr+='<li><a href="javascript:void(0)" class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off" ';
					iStr+='value = "'+io.val+'" catkey="indicator" >'+io.txt+'</a></li>';
				}
				iStr+='</ul></li></div>'
			} 
			p2.append(iStr);
			this.outObj.append(p2);
			p2 = null;
        }
		if(uc.chartCtrl == "rtqPanel"){ // add tab panel
			this.outObj.append('<div class="rtc-ul-tab clearfix"><div class="rtc-tab-zoom">'+
				'<div class="rtq-ddl" style="z-index: 2000; width: 115px;"><div val="1" style="width: 111px;" class="rtq-ddl-ipt">'+
				'</div></div></div><div class="rtc-tab"></div></div>');
			el.tabmenuZoomEl = this.outObj.find(".rtc-tab-zoom .rtq-ddl");
		}
        if (uc.Chart && uc.Chart != null && !uc.CustomUI) {
			var cc = $('<div class="rtc-chart-container rtc-price-chart"></div>').appendTo(this.outObj); // create price chart container.
			if (uc.Chart.showPChart) { // create crosshair hover window.
				if (uc.Chart.showLegend) { // add price chart legend
					el.legendElm = $('<div class="rtc-legend-txt"></div>').appendTo(cc);
				}else{
					el.legendElm = null;
				}
				cons.pChartContainer = $('<div class="rtc-chart rtc-chart-main"></div>').appendTo(cc);
				el.crosshairLegendWin = $('<div class="rtc-legend-win" style="display:none;">'+
					'<div class="rtc-legend-win-wrap"></div></div>').appendTo(cons.pChartContainer);
				el.crosshairLegendElm = el.crosshairLegendWin.find(".rtc-legend-win-wrap");
		        el.lineXElm = $('<div class="rtc-line-x"><span></span></div>').appendTo(cons.pChartContainer);
        		el.lineYElm = $('<div class="rtc-line-y"></div>').appendTo(cons.pChartContainer);
        		el.xLabelElm = el.lineXElm.find(":first-child");	
				if(uc.ZoomIn){
					el.zoomMask = $('<div style="display:none" class="chart-zoom-mask"></div>').appendTo(cons.pChartContainer);
				}	
			}
		}
		if (uc.chartCtrl == "default" && uc.vCtrl && uc.vCtrl != null) {
			var vcc =$('<div class="rtc-ctrl2"><div class="rtc-ctrl-sect"><span class="rtc-ctrl-lb2B">'+QSLGTXT.cvolume+' ('+QSLGTXT.shortmillion+')</span></div></div>');
	        if (uc.vCtrl.showSMVV) vcc.append(' <div class="rtc-ctrl-sect"><span class="rtc-ctrl-lb2B">'+QSLGTXT.movavg+'</span>'+
				'<input style="width: 40px;" class="qs-ui-ipt qs-mov-vol" type="text" /></div>'); 
	        if (uc.vCtrl.showHideLink) vcc.append('<div class="rtc-ctrl-sect" style="float: right;">'+
				'<a href="javascript:void(0)" class="rtc-ctrl-lb2B volLink">'+QSLGTXT.hide+'</a></div>');
	        this.outObj.append(vcc);
			el.volSwitchLink = this.outObj.find(".volLink").unbind("click").bind("click",function(){
				self.toggleVolumeChartVision();
				return false;
			});// hide or show volume chart.
			vcc = null;
	    } 
        if (uc.Chart.showVChart) {  // create volume chart container and legend.
			var volC = $('<div class="rtc-chart-container"></div>').appendTo(this.outObj);	
			el.volLegendElm = $('<div class="volLegend"></div>').appendTo(volC);
			cons.vChartContainer = $('<div class="rtc-chart  rtc-chart-mini"></div>').appendTo(volC);
		}else{
			this.showVolume = false;
		}		
		if (uc.Chart.showTimeSlider) {
			var mCon = $('<div class="rtc-chart-container"></div>').appendTo(this.outObj);
			cons.mChartContainer = $('<div class="rtc-chart"></div>').appendTo(mCon);
		}else{
			this.isShowTimeSlider = false;
		}    
        if (uc.chartCtrl == "rtqPanel") {
			this._createSettingPanelUI();			
		} else {
			el.indicatorULElm = this.outObj.find(".qs-indicator-list");  // container of indic
			// bind event to sma and smav input boxes.
			if(uc.pCtrl2 && uc.pCtrl2.showSMV){   
				el.m1 = this.outObj.find(".qs-mov1").val(QSLGTXT.line+" 1").css({color:"#666"});
				el.m2 = this.outObj.find(".qs-mov2").val(QSLGTXT.line+" 2").css({color:"#666"});
				el.m3 = this.outObj.find(".qs-mov3").val(QSLGTXT.line+" 3").css({color:"#666"}); 
	            el.m1.unbind("keydown").bind("keydown",function(kp){
					var keyID = (window.event) ? kp.keyCode : kp.which ? kp.which : kp.charCode;
					if(keyID==13) self.addSMA();
				});
	            el.m2.unbind("keydown").bind("keydown",function(kp){
					var keyID = (window.event) ? kp.keyCode : kp.which ? kp.which : kp.charCode;
					if (keyID == 13) self.addSMA();
				});
	            el.m3.unbind("keydown").bind("keydown",function(kp){
					var keyID = (window.event) ? kp.keyCode : kp.which ? kp.which : kp.charCode;
					if(keyID==13) self.addSMA();
				});     
				el.m1.click(function(){self.clearBox(this);});
				el.m2.click(function(){self.clearBox(this);});
				el.m3.click(function(){self.clearBox(this);});
			} 
			if (uc.vCtrl && uc.vCtrl.showSMVV) {
				el.mv = this.outObj.find(".qs-mov-vol").val(QSLGTXT.line+" 1").css({color:"#666"});
				el.mv.unbind("keydown").bind("keydown", function(kp){
					var keyID = (window.event) ? kp.keyCode : kp.which ? kp.which : kp.charCode;
					if (keyID == 13) 
						self.addIndicators("SMAV", el.mv.attr("value"));
				});
				el.mv.click(function(){self.clearBox(this);});
			}
			el.$customDate = this.outObj.find(".customRange")
			el.eventULElm = this.outObj.find(".qs-event-list");
			el.valuationULElm = this.outObj.find(".qs-valuation-list");
			el.indexsULElm = this.outObj.find(".qs-index-list");
			el.relatedSecULElm = this.outObj.find(".qs-relative-list");	
			el.tabmenuZoomEl = this.outObj.find(".rtc-tab-zoom .rtq-ddl");
		}
        if(typeof(this.afterCreateUI)=="function"){
            this.afterCreateUI();
        }
    },
	_createSettingPanelUI:function () {
		var el = this._elements,cons = this._contains,uiComps = this.uiComponents,self = this;
		cons.$settingPanel.html("");
		if (!this.UIConfig.panel.showWindow){
			this.settingGroupList.splice(1,1);
		}
		if(!this.UIConfig.panel.showNote){
			this.drawingData.splice(3,1);
		}
		var settingGroup = new Util.GroupBox(cons.$settingPanel,this.settingGroupList,{width:180,groupBoxHeight:310,autoHeight:true});
		var gb1 = settingGroup.getGroup(1).bd, bHtml="";
        bHtml+='<div class="clearfix block-row-top"><h4>'+QSLGTXT.charttype+'</h4><div class="ddlChartType"></div></div>';
		bHtml+='<div class="clearfix block-row"><h4>'+QSLGTXT.verticalscale+'</h4><div class="ratioScale"></div></div>';
		bHtml+='<div class="clearfix block-row"><h4>'+QSLGTXT.yaxis+'</h4><div class="ratioYaxis"></div></div>';
		bHtml+='<div class="clearfix block-row"><h4>'+QSLGTXT.selectionmode+'</h4><div class="ratioSelectionMode"></div></div>';
		bHtml+='<div class="clearfix block-row"><h4>'+QSLGTXT.range+'</h4><div class = "customRange clearfix" ></div></div>';
		bHtml+='<div class="clearfix block-row"><div class="set-block"><h4>'+QSLGTXT.zoom+'</h4><div class="ddlZoom"></div></div>';
		bHtml+='<div class="set-block set-right"><h4>'+QSLGTXT.frequency+'</h4><div class="ddlFrequency"></div></div></div>';
		bHtml+='<div class="clearfix block-row"><div class="set-block"><h4>'+QSLGTXT.chartcursor+'</h4><div class="ddlCursorType"></div></div></div>';
		bHtml+='<div class="clearfix block-row"><div class="set-block"><div class="iivTicker"></div></div></div>';
    	gb1.append(bHtml);
		el.$customDate = gb1.find(".customRange");
		el.$ratioScale = gb1.find(".ratioScale");
		el.$yaxisAlign= gb1.find(".ratioYaxis");
		el.$selectionMode= gb1.find(".ratioSelectionMode");
		var str ="",cls;
		
		for(var i=0;i< this.scaleTypeListData.length;i++){
			cls = i==0?"rtq-ratio-left ":"rtq-ratio-off"
			str+='<a href="javascript:void(0)" catkey="scale" class="rtc-menu-trigger rtq-ratio '+cls+' " ';
			str+='value="'+ this.scaleTypeListData[i].val+'">'+this.scaleTypeListData[i].txt+'</a>';
		}
		el.$ratioScale.html(str);
		str ="";
		for(var i = 0;i<this.yaxisAlignListData.length;i++){
			str+='<a href="javascript:void(0)" catkey="yaxis" class="rtc-menu-trigger rtq-ratio '+(i==0?"rtq-ratio-left ":"rtq-ratio-off")+' " ';
			str+='value="'+ this.yaxisAlignListData[i].val+'">'+this.yaxisAlignListData[i].txt+'</a>';
		}
		el.$yaxisAlign.html(str);
		str ="";
		for(var i = 0;i<this.selectionModeListData.length;i++){
			str+='<a href="javascript:void(0)" catkey="selectionmode" class="rtc-menu-trigger rtq-ratio rtq-menu-selectmode '+(i==0?"rtq-ratio-left ":"rtq-ratio-off")+' '+(this.selectionModeListData[i].val!="reset"?" ":"rtq-ratio-chart-reset")+'" ';
			str+='value="'+ this.selectionModeListData[i].val+'">'+this.selectionModeListData[i].txt+'</a>';
		}
		el.$selectionMode.html(str);
		el.iivContainer = gb1.find('.iivTicker');
		uiComps.chkIIV = new Util.ButtonGroup(el.iivContainer, [{txt:QSLGTXT.inav+"/"+QSLGTXT.nav,val:'showIIV'}], {
			onClick: function(v, btn){
				if(v=="showIIV"){
					self.switchIIV(btn.isSelected);
				}
			}
		},{type:'checkbox',vertical:true});
		
		var gb2 = settingGroup.getGroup(2).bd;
		gb2.append('<div class="clearfix block-row-top"><h4>'+QSLGTXT.compare+'</h4><div class="clearfix" style="position:relative">'+
			'<input  id ="'+this.autoBoxID+'" class="qs-ui-ipt" type="text" style="width: 132px;" value="" />'+
			'<a href="javascript:void(0)" class="qs-ui-btn go qs-compare-button">'+QSLGTXT.add+'</a><div></div>');	
		gb2.append('<div class="clearfix block-row"><h4>'+QSLGTXT.relatedindexes+'</h4><div class="relatedIndexs" style="height:80px"></div></div>')
		gb2.append('<div class="clearfix block-row"><h4>'+QSLGTXT.relatedsecurities+'</h4><div class="relatedSecuities"></div></div>');
		el.addCompairBtElm = gb2.find(".qs-compare-button");		
		var strr="";
		for(var o in this.indexsMap){
			strr+='<div class="check-row"><a href="javascript:void(0)" class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off" ';
			strr+='value="'+o+'" name="'+this.indexsMap[o].name+'" catkey="indexs" >'+this.indexsMap[o].txt+'</a></div>';
		}
		el.indexsULElm = gb2.find(".relatedIndexs").html(strr);
		uiComps.indexScrollPN = new Util.ScrollPanel(el.indexsULElm,{showX:false});
		settingGroup.getGroup(2).hd.bind("click.chart",function(e){
			if (uiComps.indexScrollPN != null && !self._indexScrollResized) {
				uiComps.indexScrollPN.reSize(null,80);
				self._indexScrollResized = true;
			}
		})
		el.relatedSecULElm = gb2.find(".relatedSecuities");
		var gb2 = settingGroup.getGroup(3).bd;
		var gb2str = "<div class='clearfix block-row-top'><h4></h4>";
		for(var i =0;i<this.drawingData.length;i++){
			gb2str += "<div  catkey='draw' class='rtc-menu-trigger draw-row' value="+this.drawingData[i].val+">";
			gb2str += "<a href='javascript:void(0)'>"+this.drawingData[i].txt+"</a></div>";
		}
		gb2str+="</div>";
		gb2.append(gb2str);
		el.$drawBlock = gb2.find(".block-row-top");
		var gb4 = settingGroup.getGroup(4).bd.addClass('rtq-chart-group-indi');
		uiComps.indTabMenu = new Util.TabMenu(gb4[0],this.indicatorTabList, {
            	onActive: function(tab){}
        },{ 
           width:80,
           isExcuteCallbackAtInit:false,
		   autoFixtoText:false,
           vertical: true
        });
		var str="",ilg = uiComps.indTabMenu.tabs.length;
		for(var i=0; i<ilg;i++){
			str="";
			for(var o=0;this.indicatorPanelData[i].length;o++){
				var indo = this.indicatorPanelData[i][o];
				str+='<div class="check-row"><a href="javascript:void(0)" class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off" ';
				str+=' value="'+indo.val+'" catkey="indicator" >'+indo.txt+'</a></div>';
			}
	        uiComps.indTabMenu.tabs[i].panel.append(str);
	    }	
		el.indicatorULElm = gb4.find(".rtq-tab-panels");
		gb4.css({position:"relative"}); 
		var gb5 =  settingGroup.getGroup(5).bd;
		var gb5str = "<div clearfix block-row-top><h4></h4><div class='event'>";
		for(var i = 0;i<this.eventsData.length;i++){
			var et = this.eventsData[i];
			gb5str += "<div class='check-row'><a class='rtc-menu-trigger rtq-chkbox rtq-chkbox_off' ";
			gb5str += "value='"+et.val+"' name='"+et.name+"' catkey='event' href='javascript:void(0)'>"+et.txt+"</a></div>";
		}
		gb5str +="</div></div>";
		gb5.append(gb5str);
		el.eventULElm = gb5.find(".event");
		
		var gb6 = settingGroup.getGroup(6).bd.addClass('rtq-chart-group-fund');
		uiComps.funTabMenu = new Util.TabMenu(gb6[0],this.fundamentalTabList, {
            	onActive: function(tab){}
        },{ 
           width:80,		   
           isExcuteCallbackAtInit:false,
		   autoFixtoText:false,
           vertical: true
        });
		str="";
		for(var i=0; i< uiComps.funTabMenu.tabs.length;i++){
			str="";
			for(var o=0; o<this.fundamentalPanelData[i].length;o++){
				var fda = this.fundamentalPanelData[i][o];
				str+='<div class="check-row"><a href="javascript:void(0)" class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off"';
				str+=' value="'+fda.val+'" catkey="valuation" >'+fda.txt+'</a></div>';
			}
	        uiComps.funTabMenu.tabs[i].panel.append(str);
	    }		
		el.valuationULElm = gb6.find(".rtq-tab-panels");
		
		if (this.UIConfig.panel.showWindow) {	  // add window intem to setting panel.
		    var gb7 = settingGroup.getGroup(7).bd;
	        uiComps.settingPlugin=new SettingPlugin(gb7,{className:'rtq-setting-plugin-black',width:170,showLockCheckable:false,showHideCheckable:false},{
	            onChangeTitle:function(title,isAdd,isAuto){
	                self.autoTitle = isAuto;
	                self.onChangeTitle(title,isAdd,isAuto);
	            }
	        });
			gb7.append('<div class="clearfix block-row"><div class="set-block"><div class="lock"></div></div></div>');
			uiComps.chkLock = new Util.ButtonGroup(gb7.find('.lock'), [{
				txt: QSLGTXT.showtimerangeslider,
				val: 'showTimeSlider'
			}, {
				txt: QSLGTXT.lockondoubleclick,
				val: 'lock'
			}, {
				txt: QSLGTXT.shownotes,
				val: 'showNotes'
			}], {
				onClick: function(v, btn){
					if (v == "showTimeSlider") {
						self.isShowTimeSlider = btn.isSelected;
						if (self.isShowTimeSlider) {
							cons.mChartContainer.show();
						}
						else {
							cons.mChartContainer.hide();
						}
						self.changeOutSize(self.chartWidth, self.outHeight);
					}
					else 
						if (v == "lock") {
							self.lock = btn.isSelected;
						}
						else 
							if (v == "showNotes") {
								self.showNotes = btn.isSelected;
								if (self.showNotes) {
									self._loadChartNote(self.mainTicker);
								}
								else {
									self._contains.pChartContainer.find(".qs-note-flot").remove();
								}
							}
				}
			}, {
				type: 'checkbox',
				vertical: true
			});
			uiComps.chkLock.btns["lock"].el[0].title = 'This function allows you to prevent the window from updating' +
			' when you double-click a security in the watchlist.';
		}
    },
	_createUiComponents:function() {
		var uiComps = this.uiComponents, uc = this.UIConfig, cons = this._contains, el = this._elements,self = this;
		var objref,cls = "";
		if (uc.chartCtrl == "rtqPanel") {
			objref = cons.$settingPanel;
			cls = "rtq-ddl-black", hcolor="#727272";
		} else {
			objref = this.outObj;
		}
        if (uc.pCtrl1 && uc.pCtrl1.showZoom && uiComps.ddlZoom == null) {
            uiComps.ddlZoom = new Util.DropDownList(objref.find(".ddlZoom")[0],function(k,v){self.zoomSelected(k,v);},
			 self.zoomListData, {triggerByClick:false, width:76,disable:true,actionAtInit:false,className: cls});
        }
        if (uc.pCtrl1 && uc.pCtrl1.showFrequency && uiComps.ddlFrequency == null) {
            uiComps.ddlFrequency = new Util.DropDownList(objref.find(".ddlFrequency")[0], function(k,v){self.frequencySelected(k,v);},
			 self.frequencyListData, {triggerByClick:false, width:76,disable:true, actionAtInit:false,className: cls});
        }
        if (uc.chartCtrl == "rtqPanel" && uc.pCtrl2 && uc.pCtrl2.showCursorType && uiComps.ddlCursorType == null) {
            var w = uc.chartCtrl=="default"?75:165;
			uiComps.ddlCursorType = new Util.DropDownList(objref.find(".ddlCursorType")[0], function(k,v){self.cursorTypeSelected(k,v);},
			 self.cursorTypeListData, {triggerByClick:false, width:w,disable:true, actionAtInit:false,className: cls});
        }
        if (uc.pCtrl2 && uc.pCtrl2.showChartType && uiComps.ddlChartType == null) {
			var w = uc.chartCtrl=="default"?105:165;
            uiComps.ddlChartType = new Util.DropDownList(objref.find(".ddlChartType")[0], function(k,v){self.chartTypeSelected(k,v);},
			 self.chartTypeListData, {triggerByClick:false, width:w, disable:true,actionAtInit:false,className: cls});
        }
		this._createIndicatorInputWin(this.outObj); // create indicator input window.
		if(uc.chartCtrl == "rtqPanel"){  // create tab menu.
			this._createTabMenu();
		}
		if (uc.RightMenu) {    // create right menu for price chart and mini-chart.
			this._createRightMenu(cons.pChartContainer);
			this._createIChartRightMenu();
		}
		if (uc.pCtrl1 && uc.pCtrl1.showTimeRange) { // create customize date boxes.
			this._createDateInputBoxes();
		}
    } ,
	autoCPCallback:function(o){
        this.acceptTicker(o);
    },

	requestRelateSec:function(){  // request relative securities for subject ticker.
		var t = this.tickerInfos[this.mainTicker];
		var tt = t["ticker"], gkey = t["gkey"];
		var rg = typeof(gData)== "undefined"||!gData[gkey]?t["country"]:gData[gkey]["country"];
		var url = this.dataUrl.relatiedSecURL+'&t='+tt+'&region='+rg;
		var self = this;
		$.getJSON(url+"&cb=?",function(d){
            self.buildRelatedSec(d);
        });
	},
	buildRelatedSec: function(data){
		if(data == null || !data.length) return;
		var str="",self = this;;
		for(var i=0;i<data.length; i++){
			if(data[i].PID == this.mainTicker)continue;
			str += '<div class="check-row"><a catkey="relateSec" name="'+data[i].Name+'" value="'+data[i].PID+'"';
			str += ' class="rtc-menu-trigger rtq-chkbox rtq-chkbox_off" href="javascript:void(0)">'+data[i].Name+'</a></div>';
		}		
		this._elements.relatedSecULElm.html(str).find(".rtc-menu-trigger").click(function(){
			self.menuButtonClicked(this);
		});
		if(this.compairTickers.length){
			for(var i=0;i<this.compairTickers.length;i++){
				this._elements.relatedSecULElm.find("a[value='"+this.compairTickers[i]+"']").removeClass("rtq-chkbox_off");
			}
		}
	},
	initComponent:function() { // init component state.
		var self = this;
        this._attachUIEvents();
		if(this.UIConfig.chartCtrl == "rtqPanel"){
			this.requestRelateSec();
		}
        this._initUiComponentsStatus(); // init the status of UI controls.
        this.chartData.DataList = this.chartData.VolList = this.chartData.eventDataList = null;
        for(var o in this.iChartData){
			this.iChartData[o] = [];
		}
        this.initStartDate();
		if (typeof(this.setTitle)=="function") {
	        var t = this._getClientTicker(this.mainTicker);//this.tickerInfos[this.mainTicker]["ticker"];
	        this.setTitle(this._title,t);
	    }
        this.changeRange(this.zoomRange);
        setTimeout(function() {self.getSilderChartData();},200);
    },

	_attachUIEvents: function () {  // bind events to price chart and volume chart legends.
		var el = this._elements, self = this, cons = this._contains;
		if (el.legendElm != null) {
			el.legendElm.unbind().bind("mouseover.rtqChart", function(e){ // mouse over price chart legend.
				var t = $(e.target);
				if (e.target.tagName.toUpperCase() == "SPAN" || t.hasClass("rtc-legend")) {
					var elm = t.closest(".rtc-legend");
					el.legendElm.find(".rtc-legend-remove").removeClass("rtc-legend-remove");
					if (elm.attr("name") != "MReturnIndex") 
						elm.addClass("rtc-legend-remove"); // not dividend effect chart legend
				}
				else {
					el.legendElm.find(".rtc-legend-remove").removeClass("rtc-legend-remove");
				}
			}).bind("mouseout.rtqChart", function(e){ // mouse out legend.
				el.legendElm.find(".rtc-legend-remove").removeClass("rtc-legend-remove");
			}).bind("click.rtqChart", function(e){
				var t = $(e.target);
				if (e.target.tagName.toUpperCase() == "SPAN" || t.hasClass("rtc-legend")) {
					var elm = $(e.target).closest(".rtc-legend");
					self.legendOnClick(elm);
				}
			});
		}
		if (el.volLegendElm != null) {
			el.volLegendElm.unbind().bind("mouseover.rtqChart", function(e){
				var t = $(e.target);
				if (e.target.tagName.toUpperCase() == "SPAN" || t.hasClass("rtc-legend")) {
					var elm = t.closest(".rtc-legend");
					el.volLegendElm.find(".rtc-legend-remove").removeClass("rtc-legend-remove");
					elm.addClass("rtc-legend-remove");
				}
				else {
					$(this).addClass("rtc-legend-remove");
				}
			}).bind("mouseout.rtqChart", function(e){
				el.volLegendElm.find(".rtc-legend-remove").removeClass("rtc-legend-remove");
				$(this).removeClass("rtc-legend-remove");
			}).bind("click.rtqChart", function(e){
				var t = $(e.target);
				if (e.target.tagName.toUpperCase() == "SPAN" || t.hasClass("rtc-legend")) {
					var elm = $(e.target).closest(".rtc-legend");
					self.legendOnClick(elm);
				}else {
					self.switchVolumeChart(false); //close the volmue chart.
					if (self.indicatorsData["VPlus"].show) {
						self.indicatorsData["VPlus"].show = false;
						self.changeRightMenuClass(2, "VPlus", false);
						el.indicatorULElm.find("a[value='VPlus']").addClass("rtq-chkbox_off");
					}
					else 
						if (self.indicatorsData["Volume"].show) {
							self.indicatorsData["Volume"].show = false;
							self.changeRightMenuClass(2, "Volume", false);
							el.indicatorULElm.find("a[value='Volume']").addClass("rtq-chkbox_off");
						}
					self.indicatorsData["SMAV"].show = false;
					self.indicatorsData["SMAV"].num = null;
					el.indicatorULElm.find("a[value='SMAV']").addClass("rtq-chkbox_off");
					self.changeRightMenuClass(2, "SMAV", false);
					if(typeof(self.afterRemoveVolumeChart)=="function"){
						self.afterRemoveVolumeChart();
					}
				}
			})
		}
		var $compare = $("#"+this.autoBoxID);
        if (this.UIConfig.pCtrl1 && this.UIConfig.pCtrl1.showCompair && $compare.length > 0) {  // init compair section   	
			if (typeof(GB_qsAutoCompleteBox) == "object") {
				GB_qsAutoCompleteBox.subscription(this.autoBoxID,function(line){			
					self.validateCompairTicker(line);
				},{needClear:true});
			}
			if (this.UIConfig.chartCtrl != "default") {
				$compare.css({color: "#DFDFDF"});
			}
            $compare.val("Enter Security").click(function(){self.clearBox(this);});
            el.addCompairBtElm.unbind("click").click( function(){          // add compare ticker button.
		        var tic = $("#"+self.autoBoxID).attr("value");
		       // if (tic != null && tic != "") {
					//self.validateCompairTicker(tic);
					GB_qsAutoCompleteBox.triggerACB(self.autoBoxID);
		        //}
			});
        }
		this.outObj.find(".rtc-menu-trigger").unbind("click").click(function(){  // bind events to list items.
            if(self.mainTicker!="" && self.mainTicker!=null){
				self.menuButtonClicked(this);
			} 
        });
		if(this.UIConfig.chartCtrl=="rtqPanel"){							// bind events to list items in setting panel.
	        cons.$settingPanel.find(".rtc-menu-trigger").unbind("click").click(function(){
				if(self.mainTicker!=""&& self.mainTicker!=null){
					self.menuButtonClicked(this);
				} 
	        });
		}  
        this.attachMouseScoll();  
		this.attachZoomIn();           
    },
	addSMA: function(){
		var el = this._elements;
		this.addIndicators("SMA",el.m1.val(),el.m2.val(),el.m3.val());
	},
	clearBox:function(obj) {
        if (obj == null) {
            return;
        }
        var v=$(obj).val(); 
        if(v.substring(0,4) == "Line" || v== "Enter Security") {
            $(obj).val("");
			//$(obj).css("color","#333333");
        }
		if(this.UIConfig.chartCtrl=="rtqPanel"){
			$(obj).css("color","#DFDFDF");
		}
    },
	getTickerInfo:function(pid){ 
		if(typeof(gIdMap)!= "undefined" && typeof(gData)!= "undefined"){  //QSII terminal
			return gData[gIdMap[pid]];
		} else {
			return this.tickerInfos[pid];
		}
	},
	initStartDate: function() {
		//var y = this.latestTradeDate.getFullYear(), m = this.latestTradeDate.getMonth(), d = this.latestTradeDate.getDate();
		var d = GB_ChartDataManager.dates;
		this.sDates.iMin = d[1];//new Date(y,m,d-5);
		this.sDates.sMin = d[5];//new Date(y,m-1,d-2);
		this.sDates.lMin = d[10];//new Date(y,m-3,d-10);
        this.sDates.d = d["d"];//new Date(y-2,0,1);
        this.sDates.w = d["w"];//new Date(y-20,0,1);
        this.sDates.m = d["m"];//new Date(1900,0,1);
        this.slider_StartDate = this.getSliderStartDate();  
    },
	getPidByExchAndTicker: function(symbol){  // get PID 
		var t = symbol.split(":");
		if(t.length < 2){
			if(this.mainTicker == symbol){
				return symbol;
			}else{
				for(var i = 0;i < this.compairTickers.length; i++){
					if(this.compairTickers[i] == symbol){
						return this.compairTickers[i];
					}
				}
			}
		} else if(typeof(this.tickerInfos) == "object"){
			for(var o in this.tickerInfos){
				if(this.tickerInfos[o]["gkey"]== symbol||(this.tickerInfos[o].exch == t[0]&&this.tickerInfos[o].ticker == t[1])){
					return o;
				}
			}
		}
	},
	_setSizeParas: function(wd,hg){
		this.chartWidth = wd;
		this.outHeight = hg;
        var ih = this.getIChartsHeight();
        var h = hg-ih-25;  // slider chart :30px, subject chart legend height:25px.
        if (this.isShowTimeSlider) {
			h = h - 30;
		}
        if (this.UIConfig.chartCtrl == "default") {
             if (this.UIConfig.pCtrl1 != null ) h -= 28;
             if (this.UIConfig.pCtrl2 != null ) h -= 28;
             if (this.UIConfig.vCtrl != null) h-= 28;
        } else if (this.UIConfig.chartCtrl == "rtqPanel") {
             h-=30;  // tab menu height.
        }
        var hh = h>this.minH?h:this.minH;
        var ph= hh - this.iChartHeight;
        var vh = this.iChartHeight - 20;
		if(!this.showVolume){
			vh = 0;
			ph = hh;
		}
        this.pChartHeight = ph;
        this.vChartHeight = vh;
	},
	_calFrequencyByRange: function(){
		var days  = (this.endDate.getTime()-this.startDate.getTime())/86400000;
		return days;
	},
	calculateFrequency: function(startDate) {   // calculate frequency by range and start Date.
       var f = "minute", range = this._calFrequencyByRange(), s = this.startDate;
	   if(s >=this.sDates.iMin || (range <= 5 && this.startDate >=this.sDates.lMin)) f="minute";
	   else if (s >= this.sDates.sMin || (range < 30&&s >= this.sDates.lMin)) f="minute5";
	   else if (s >= this.sDates.lMin)f="minute10"
       else if (s >= this.sDates.d) f = "d";
       else if (s >= this.sDates.w) f = "w"; 
	   else f= "m" ;
       return f;
    },
	changeFrequencyStyle: function(num) {
        var uiComps = this.uiComponents, el = this._elements, f, mf ;
        if (num == 1 || num == 2||num==0) {  // 0: 3 days
			f = "minute";
            if (this._frequencyIndexMap[this.frequency] > 0) {
				this.frequency = f;
			}
			mf="minute"; 
        } else { 
            f = this.calculateFrequency(this.startDate); 
			mf = f;
        }
        this.changeFrequency(f);
		if (uiComps.rightMenu != null) { 
            uiComps.rightMenu.changeUIState(num,"zoom",true);
        }
		if(uiComps.tabZoomMenu !=null){
			uiComps.tabZoomMenu.changeUIState(num,null,true);
			el.tabmenuZoomEl.find(".rtq-ddl-ipt").html(this.zoomListData[this._zoomIndexMap[num]].txt+" | "+this._frequencyTxtMap[this.frequency]);
		}
		if(this.noHistoricalData) mf = "minute";  // no historical data for chart.
        if (this._frequencyIndexMap[mf] > 0 && mf != this.miniChartFrequency) {  //slider chart view changed
            this.miniChartFrequency = mf;
			this.getSilderChartData();
        }else if(this._frequencyIndexMap[mf] <= 0&& this.miniChartFrequency != "minute"){//slider chart view changed
			this.miniChartFrequency = "minute";
			this.getSilderChartData();
		}else{
			this.setSliderHandleValues();
		}
    },
	changeFrequency: function(f) {
        if (this._frequencyIndexMap[f] > this._frequencyIndexMap[this.frequency]) {
			this.frequency = f;
		}else if ((this.zoomRange == 13||this.zoomRange == 3)&&this._frequencyIndexMap[this.frequency] > 1 ) {// 15 days or 1 mth
			this.frequency = "d";
		}else if((this.zoomRange == 14||this.zoomRange == 4)&&this._frequencyIndexMap[this.frequency] > 2){// 2 mth or 3 mth
			this.frequency = "w";
		}else if (this.zoomRange==11){
			if((f == "minute" && this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["d"]))this.frequency = f;
			else if(f == "minute5"&&this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["w"])this.frequency = "d";
			else if (f == "minute10"&&this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["m"])this.frequency = "w";
			else if(f == "minute10"&&this.frequency == "minute15")this.frequency = "minute30";  // not contains 15 minute frequency.
		}
        if (this.UIConfig.pCtrl1 == null || !this.UIConfig.pCtrl1.showFrequency) {
            if(!this.customizeFreq){
                this.frequency = f; 
            }
        }// if can't exist frequency control element
        this.bindFrequencyMenu(f);
    },
	bindFrequencyMenu: function(f) {
        if (this.UIConfig.pCtrl1 == null || !this.UIConfig.pCtrl1.showFrequency) { 
            return;
        }
        var st = this._frequencyIndexMap[f],uiComp = this.uiComponents, el = this._elements;
		if(st!= this.selectFreIndex){
			if(st <= -4||this.zoomRange<3) {
				uiComp.ddlFrequency.rebindData(this.intradayFreMenuData);
	        }else if(st<=-3){                  // 5, 10,15,30,d
				uiComp.ddlFrequency.rebindData(this.sMinuteFreMenuData);
			}else if(st<=0){                   // 10,30,d
				uiComp.ddlFrequency.rebindData(this.lMinuteFreMenuData);
			}else if(st==1){
				uiComp.ddlFrequency.rebindData(this.dailyFreMenuData);
	        } else if(st==2){
				uiComp.ddlFrequency.rebindData(this.weeklyFreMenuData);
			}else if(st==3){
				uiComp.ddlFrequency.rebindData(this.monthlyFreMenuData);
			}
			this.selectFreIndex = st;
		}  
        if(uiComp.ddlFrequency != null) {
            uiComp.ddlFrequency.setTextValue("",this.frequency);
			if (uiComp.rightMenu != null) {
				uiComp.rightMenu.changeUIState(this.frequency,this.zoomRange,true);
			}
			if(uiComp.tabZoomMenu!=null){
				uiComp.tabZoomMenu.changeUIState(this.frequency,this.zoomRange,true);
				var ss = this.zoomListData[this._zoomIndexMap[this.zoomRange]].txt+" | "+this._frequencyTxtMap[this.frequency];
				el.tabmenuZoomEl.find(".rtq-ddl-ipt").html(ss);
			}
        }
    },
	buildVolLegend: function(dataIndex){
		var volstr="",leg,val,name, cd = this.chartData;
		if(!this.showVolume||!cd.VolList||!cd.VolList.length)return;
		for(var i = 0; i < cd.VolList.length;i++){
			leg = cd.VolList[i].legend, name = cd.VolList[i].name;
			if(dataIndex != null&&dataIndex > -1) {
                val = this.getVolInfo(dataIndex);
            }else{
				val = "";
			}
			volstr +=this.createLegendSpan((i==0?0:2),leg,val,(i==0?-1:i),('name='+name));  // -1 :volume
		}
		this._elements.volLegendElm.html(volstr);
	},
	toggleVolumeChartVision: function() {
        if (this.showVolume) {
            if (this.UIConfig.chartCtrl == "default") this._elements.volSwitchLink.html(QSLGTXT.show);
        } else if (!this.showVolume) {
            if (this.UIConfig.chartCtrl == "default") this._elements.volSwitchLink.html(QSLGTXT.hide);
        }
		var flag = this.showVolume?0:1;
		this.switchVolumeChart(flag);
    },
	_upMiniFrequency: function() {  
        var f;
		if(this.miniChartFrequency == "minute"){
			f = "d";
		} else if (this.miniChartFrequency == "d") {
            f = "w";
        } else if (this.miniChartFrequency == "w") {
            f = "m";
        } else {
            f ="m";
        }
        return f;
    },
	switchVolumeChart: function(bshow) {  // show or hide the volume chart.
		var cons = this._contains, el = this._elements;
        if(this.showVolume != (bshow == 1)) {
            this.showVolume = (bshow == 1);
            if (this.showVolume) {
	            cons.vChartContainer.show();
				el.volLegendElm.show();
	            this.pChartHeight = this.pChartHeight - this.iChartHeight; 
				this.vChartHeight = this.iChartHeight-20;  // legend:20
	            cons.pChartContainer.css("height",this.pChartHeight); 
	            cons.vChartContainer.css("height",this.vChartHeight);
	            if(this.pFlot != null) {
	                this.pFlot.changeOutSize(this.chartWidth,this.pChartHeight);
	            }
	            if(this.vFlot != null) {
	                this.vFlot.changeOutSize(this.chartWidth,this.vChartHeight);
	            }
	        }else {
	            this.pChartHeight = this.pChartHeight + this.iChartHeight, this.vChartHeight = 0; 
	            cons.pChartContainer.css("height",this.pChartHeight); 
	            cons.vChartContainer.css("height",this.vChartHeight); 
	            if(this.pFlot != null) {
	                this.pFlot.changeOutSize(this.chartWidth,this.pChartHeight);
	            }
	            cons.vChartContainer.hide();
				el.volLegendElm.hide();
			}
			if(this._elements.zoomMask!=null)this._elements.zoomMask.css({height:this.pChartHeight+"px"});
			if(typeof(this.volumeChartChanged) == "function" ){
				this.volumeChartChanged({showVolumeChart:this.showVolume});
			}
        }
    },
	addValuations: function(name){
		if(this.valuations[name]&& name != "FairValue"){
			if(this.UIConfig.autoHeight && !this.valuations[name].show) {
	            this.outHeight += this.iChartHeight;
	        }
			this.valuations[name].show = true;
	        this.setSize(this.chartWidth,this.outHeight);
	        if(this.pFlot != null){ 
	            this.pFlot.resizeCanvas(this.chartWidth,this.pChartHeight);
	        }
	        if(this.vFlot != null && this.showVolume) {
	           this.vFlot.resizeCanvas(this.chartWidth,this.vChartHeight);
	        }
			this.drawPChart();
			this.drawVChart();
			this.getIChartData(name);
			if(typeof(this.afterAddValuationCallback)=="function"){
				this.afterAddValuationCallback({name:name});
			}
		}else{
			this.valuations[name].show = true;
			this.getIChartData(name);
		}
	},
	removeValuations: function(name){
		if (this.valuations[name]) {
			this.valuations[name].show = false;
			if(name=="FairValue"){
				this._removeDataRowFromDataList(name);
				this.drawPChart();
			}else{
				this.removeIChart(name);
				if(typeof(this.afterRemoveValuationCallback)=="function"){
					this.afterRemoveValuationCallback({name:name});
				}
			}	
		}
	},
	refreshIntradayChart: function(type){
		if(this.zoomRange < 3||(this.frequency=="d"&&RTQ_ChartUtil.compareDateByday(this.endDate,this.latestTradeDate))){// daily or intrady chart.
			if (type == "p") {// refresh price chart
				this.getPChartData();
				for(var o in this.indicatorsData){
					if(this.indicatorsData[o].type == 1 && this.indicatorsData[o].show){  // refresh indicator chart.
						this.getIChartData(o);
					}
				}
			}else if(type == "v"){ //refresh volume chart
				this.getVChartData();
			}
		}
	},
	refreshLastTradeDate: function(sdate,date){  // sdate is the first date of lastest five days date.
		if(this.latestTradeDate == date)return;
		this.slider_EndDate = this.latestTradeDate = date;
		if(sdate!=null)this.sDates.iMin = sdate;
		if(this.zoomRange != 11){
			if(this.zoomRange == 1) this.startDate = this.latestTradeDate;
			this.endDate = this.latestTradeDate; // change the date in custom date boxes.
			if(this.uiComponents.customDateB != null)this.uiComponents.customDateB.setDate(this.startDate,this.endDate);
			var isDefault = this.UIConfig.chartCtrl =="default"?true:false;
			this.buildLegend(null,null,true,isDefault); //change the date in chart legend.
		}
	},
	
	getPChartData:function(successCallback){
		var self = this;
		this.pChartReady = false; // request chart data for price  chart.
		var option = [], ty = this.compairTickers.length > 0 ? "return":"price"; 
		if(this.chartStyle == "growth"||this.chartStyle == "dEffect"||this.chartStyle=="growth10") ty = "return";
		var mainType = ty=="return"?"return4":ty;
		if(this.chartStyle == "growth10"){
			ty+="_k",mainType+="_k";
		}
		var ls = {symbol:this.mainTicker,datapoints:{p:mainType,v:this.showVolume,
			indicators:[]
		}};
        if(this.chartStyle == "postTax"){
                ls = {symbol:this.mainTicker,datapoints:{postTax:"return",v:this.showVolume,
                indicators:[]
            }};
        }
		if(this._frequencyIndexMap[this.frequency]>0){  // daiy, weekly, monthly.
			if(this.events.dividend || this.events.splits){
				ls.datapoints.ds= {isD: this.events.dividend ,isS: this.events.splits};
			}
			if(this.events.earnings){
				ls.datapoints.e = true;
			}
		}
		if(this.chartStyle == "dEffect"||this.chartStyle == "growth10"){  // dividend effect chart.
			if(this.indicatorsData["SMAV"].num!=null){
				ls.datapoints.indicators.push({name:"SMAV",p:[this.indicatorsData["SMAV"].num],vtype:"price"});
			}
			option.push(ls);
			if(this.chartStyle == "growth10"){
				if(this.compairTickers.length){
					for(var j = 0; j< this.compairTickers.length;j++){
						option.push({symbol:this.compairTickers[j],datapoints:{p:ty}});
					}
				}
			}
		}else{
			for(var o in this.indicatorsData){  // add overlayer chart data option.
				if(this.indicatorsData[o].type == 0){ 
					if(o=="EMA"||o=="SMA"){
						for(var i=0;i<this.indicatorsData[o].num.length;i++){
							if(this.indicatorsData[o].num[i]!=null){
								ls.datapoints.indicators.push({name:o,p:[this.indicatorsData[o].num[i]],vtype:ty});
							}
						}
					}else if(o == "SMAV"&&this.indicatorsData[o].num!=null){
						ls.datapoints.indicators.push({name:o,p:[this.indicatorsData[o].num],vtype:"price"});
					}else if(this.indicatorsData[o].show&&o!="Volume"){ 
					    if(o=="PrevClose"&&(this.zoomRange!=1||this.compairTickers.length>0||this.chartStyle=="growth"||this.chartStyle=="growth10"||this.chartStyle=="dEffect"))continue;  // only draw it  1 days chart.
						ls.datapoints.indicators.push({name:o,p:this.indicatorsData[o].parameter,vtype:ty});
					}
				}
			}
			option.push(ls);
			if(this.sType == "FE"&&this.showIIVTicker&&this.iivTicker!=""){ // for ETF 
				option.push({symbol:this.iivTicker,datapoints:{p:ty}});
			}		
			if(this.compairTickers.length){
				for(var j = 0; j< this.compairTickers.length;j++){
					option.push({symbol:this.compairTickers[j],datapoints:{p:ty}});
				}
			}
		}	
		var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
   		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
		if((typeof(this.showLoading) == 'function')) {// show loading img
			this.showLoading();
		}
		if(this._frequencyIndexMap[this.frequency]>0){  // historical
			GB_ChartDataManager.getHistoricalData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
				self.pChartDataReady(data,successCallback)});
		}else{
			if(this.zoomRange<3){
				for(var k = 0;k < option.length;k++){
					option[k].days = this.zoomRange==1?1:(this.zoomRange==0?3:5);// 0: 3 days, 1: 1 days, 2:5 days.
				}	
			}
			GB_ChartDataManager.getIntradayData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
				self.pChartDataReady(data,successCallback)});
		}
	},
	getVChartData: function(){
		var ls = {symbol:this.mainTicker,datapoints:{v:this.showVolume}}, self = this;
		if(this.indicatorsData["SMAV"]&& this.indicatorsData["SMAV"]["num"]!=null){
			ls.datapoints.indicators = [{name:"SMAV",p:[this.indicatorsData["SMAV"]["num"]],vtype:"price"}];
		}
		var option = [ls];
		var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
   		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
		if(this._frequencyIndexMap[this.frequency]> 0){  // historical
			GB_ChartDataManager.getHistoricalData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
				self.vChartDataReady(data);
			});
		}else{
			if(this.zoomRange < 3){
				option[0].days = this.zoomRange == 1?1:5;
			}
			GB_ChartDataManager.getIntradayData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
				self.vChartDataReady(data);
			});
		}
	},
	getSilderChartData: function(){
		var dx=5, m = this.miniChartFrequency, startIndex=null, endIndex = null, self = this;
		if(this.miniChartFrequency == "minute"){
			dx = 1, m = "d";
			startIndex = RTQ_ChartUtil.toDateIndex(this.sDates.lMin), endIndex = RTQ_ChartUtil.toDateIndex(this.slider_EndDate);
		}
		var option = [{symbol:this.mainTicker,dx:dx,datapoints: {p:"price"}}];
		if(this.miniChartFrequency == "minute"){
			GB_ChartDataManager.getIntradayData(option,1440,startIndex,endIndex,function(data){
				self.sliderChartDataReady(data)		
			});
		}else{
			GB_ChartDataManager.getHistoricalData(option,m,startIndex,endIndex,function(data){
				self.sliderChartDataReady(data)		
			});
		}
		
	},
	vChartDataReady: function(data){
		this.chartData.VolList = []
		if (data&&data.length&&data[0].volume){
			this.chartData.VolList.push({data: data[0].volume.data,name: "volume",startPos: null,legend: QSLGIN.volume_lg});
			if (data[0].indicators && data[0].indicators && data[0].indicators["SMAV"]){
				var leg = QSLGIN.smav_lg+"("+this.indicatorsData.SMAV.num+")";
				this.chartData.VolList.push({data:data[0].indicators["SMAV"].data,startPos:null,name:"SMAV",legend:leg});
			}
			if(this.zoomInMode==1&&this.zoomIndexRange){  // zoom in one day chart.
	            this._zoomInData(this.zoomIndexRange.s,this.zoomIndexRange.e,this.chartData.VolList);
	        }
			this.drawVChart();
			this.mouseOutChart();
		}
	},
	getIChartData: function(sName){
		var cd = this.chartData,self = this;
		if(this.iChartData[sName]||sName=="FairValue"||sName == "MReturnIndex"){
			var option;
			var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
       		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
			if(this.indicatorsData[sName]||sName=="RDividend"||sName=="DYield"){
				var par = sName=="RDividend"||sName=="DYield"?[]:this.indicatorsData[sName].parameter;
				option =  [{symbol:this.mainTicker,datapoints: {indicators: [{name: sName,p: par,vtype:"price"}]}}];
				if(this._frequencyIndexMap[this.frequency]>0){  // historical
					GB_ChartDataManager.getHistoricalData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
						self.iChartDataReady(data);
					});
				}else{
					if(sName=="RDividend"){
						this.iChartData[sName]=[{data:[],spos:null}];
						this.drawIChart(sName);
					}else{
						if (this.zoomRange < 3) {
							option[0].days = this.zoomRange == 1 ? 1 : 5;
						}
						GB_ChartDataManager.getIntradayData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
							self.iChartDataReady(data);
						});
					}
				}
			}else if(this.valuations[sName]|| sName == "MReturnIndex"){
				if(this.zoomRange>2){
					option = {symbol:this.mainTicker,fields:[sName]};
					var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
		       		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
					GB_ChartDataManager.getFundamentalData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
							self.iChartDataReady(data);
						});
				}else{
					if(sName != "FairValue"){
						this.iChartData[sName]=[{data:[],spos:null}];
						this.drawIChart(sName);
					}
				}		
			}
		}
	},
	drawChartSegment:function(){
		this.chartData.fairValueData = null;
		var self = this;
		this.getPChartData(function(){
			for(var o in self.indicatorsData){
				if(self.indicatorsData[o].type==1&&self.indicatorsData[o].show){
					self.getIChartData(o);
				}
			}
			for(var o in self.valuations){
				if((self.valuations[o]&& self.valuations[o].show)){
					self.getIChartData(o);
				}
			}
		});
	},
	drawPChart:function() { // draw price chart.
		var cd = this.chartData, self = this, cons = this._contains, el = this._elements;
        if (cd.DataList == null || cd.DataList.length < 1) { 
            return;
        }
        this.mouseOutChart();
		var dlist = cd.DataList[0].data,dlen = dlist?dlist.length:0;
		var isSameDay = false;
		if(this._frequencyIndexMap[this.frequency]<=0&&dlen>0)isSameDay = RTQ_ChartUtil.compareDateByday(new Date(dlist[dlen-1][dlist[dlen-1].length-1]), new Date(dlist[0][dlist[0].length-1]));
        if (this.zoomRange > 2&&!isSameDay) { // historical
            this.ticksize = null, this.Ticks = this.getTicks(cd.DataList[0].data,this.frequency);
			this._isIntradayTimSyle = false;
        } else {
           this.Ticks = null;
		   if(this.zoomRange==1||isSameDay) this._isIntradayTimSyle = true;
		   else this._isIntradayTimSyle = false;
		   if(this.zoomInMode==1){
               this.ticksize = Math.round(dlen/4);
           }else{
               this.ticksize = (this.zoomRange==1||(isSameDay&&this.zoomRange==11))?60/this._frequencyMap[this.frequency]:cd.DataList[0].data.length/(this.zoomRange==0?3:5);
           }
		   this.xLabelAlign = (this.zoomRange==1||(isSameDay&&this.zoomRange==11)?"left":"center");
        }
        if (this.pFlot == null) { 
            this.pFlot = new mstar.flot(cons.pChartContainer,this.getChartOption("priceLine"));
			this.pFlot.setOption({imageHighlight:this.chartCursor==0});
            cons.pChartContainer.unbind("plothover").bind("plothover", function(event, pos, item){
									 		self.buildLegend(item,pos,false,false);
										});
            cons.pChartContainer.unbind("mouseout").bind("mouseout", function(e) { 
			   if(Util.contains(cons.pChartContainer[0],e.relatedTarget)) return false;
			   else {
			   		if(self.timeout)clearTimeout(self.timeout);
			   		self.chartMouseOut();
			   }
			} );
            cons.pChartContainer.unbind("mouseover").bind("mouseover", function() {
				if(self.timeout)clearTimeout(self.timeout);
                var d = $(document);
                var l = d.scrollLeft(), t= d.scrollTop();   // consider the scroll bar of document.
                var offst = cons.pChartContainer.offset();
				self.chartOffset = {left:offst.left+l,top:offst.top+t};
				el.lineXElm.css({width:self.chartWidth});
				el.lineYElm.css({height:cons.pChartContainer.height()});
			} );
			cons.pChartContainer.unbind("drawEnd").bind("drawEnd",function(e,drawType){ 
				if (el.$drawBlock != null&& el.$drawBlock.length) {
					el.$drawBlock.find("[value='" + drawType + "']").removeClass("draw-row-select");
				}
				self.isDrawing = false;
				if(self.chartCursor==1){
					el.crosshairLegendWin.show();
				}
				if(typeof(self.afterDrawEnd)== "function"){
					self.afterDrawEnd(drawType);
				}
			});
        }
        var data = [];
        var w = 1, cloIndx;  // w is line width.
        for (var i = 0; i < cd.DataList.length; i++) { 
            w = i == 0?2:1;
			cloIndx = cd.DataList[i].colorIndex == null ?i:cd.DataList[i].colorIndex;
			if(cd.DataList[i].name == "FairValue" && this.compairTickers.length){
				continue;
			}
			if(cd.DataList[i].name == "PSAR"){
				data.push(this.getChartData(cd.DataList[i].data,"points",1,cd.DataList[i].colorIndex,1));
				continue;
			}
			if(cd.DataList[i].name == "VBP"){
				data.push(this.getChartData(cd.DataList[i].data,"VBPBar",1,cd.DataList[i].colorIndex,1));
				continue;
			}
			var sty = "line";
            if (i == 0) {   // subject ticker.
            	var sy = this.chartStyle;
				sty = sy == "mountain"||sy=="growth"||sy=="growth10"||sy=="dEffect"||sy=="postTax"?"mountain":this.chartStyle;
            }
			data.push(this.getChartData(cd.DataList[i].data,sty,1,cloIndx,w));
			if(cd.DataList[i].name=="PrevClose"){
				data[data.length-1].showLegend=true;
				data[data.length-1].legendLabel=QSLGIN.prevclose_lg;//"Prev Close";
			}
        }
        if (this.zoomRange > 2&&this._frequencyIndexMap[this.frequency]>0 &&
			(this.events.dividend || this.events.splits||this.events.earnings) &&
			 cd.eventDataList != null && cd.eventDataList.length > 0) {  //historical data;
            	data.push(this.getChartData(cd.eventDataList,"img",1,null)); 
        }
		var cs = this.chartStyle;
		var scal = (this.scaleType == "1" && (this.compairTickers.length > 0||cs=="growth"||cs=="dEffect"))?0: parseInt(this.scaleType,10);
		var drawingAble = true, unit = cs=="growth10"?"k":"";
		if(cs=="mountain"||cs=="line"||cs=="dot"||cs=="ab"||cs=="growth"||cs=="growth10"||cs=="dEffect"){
			var ct = (cs=="growth"||cs=="growth10"||cs=="dEffect")?"mountain":cs;
			this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
				lines:{lineType:ct},yaxis:{scaleType:scal},drawingAble:drawingAble});
		}else if(this.chartStyle=="ohlc"||this.chartStyle=="hlc"){
			 this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
			 	OLHC:{olhcType:this.chartStyle},yaxis:{scaleType:scal},drawingAble:drawingAble});
		}else{
			 this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
			 	yaxis:{scaleType:scal},drawingAble:drawingAble});
		}   
		this.pFlot.setOption({yaxis:{align:this.yaxisAlign,unit:unit},otherInfo:{ticker:this.mainTicker}});
        this.pFlot.init(data); 
        this.pChartReady = true;  
    },
	drawVChart: function() {  // draw volume chart. volChartContainer,VolList
		var cd = this.chartData, self = this, cons = this._contains, el = this._elements;
        if(cd.VolList == null || !cd.VolList.length ||!this.showVolume) return;
        var data = [];
        for (var i = 0;i < cd.VolList.length; i++) {
            if(cd.VolList[i].name=="volume")data.push(this.getChartData(cd.VolList[i].data,"bars",1,this.fillColors.vChart));
			else if(cd.VolList[i].name=="SMAV")data.push(this.getChartData(cd.VolList[i].data,"line",1,1,1));// smav.
        }
		var isColorBar = (this.indicatorsData["VPlus"].show)?true:false;	
        if (this.vFlot == null) {
            this.vFlot = new mstar.flot(cons.vChartContainer,this.getChartOption("volumeBar"));
			if(this.UIConfig.RightMenu){
				cons.vChartContainer.bind("contextmenu",function(e){ // add right menu
				});
			}
        }
        this.vFlot.setOption({yaxis:{align:this.yaxisAlign},xaxis:{tickSize:this.ticksize,ticks:this.Ticks},bars:{isColorBar:isColorBar}}); // change the xaisx labels;
        this.vFlot.init(data);
		this.buildVolLegend(-1);
    },
	drawSliderChart:function() {
		var  cons = this._contains;
        if (this.UIConfig.Chart == null || (!this.UIConfig.Chart.showTimeSlider && !this.UIConfig.CustomUI)) {
            return;
        }
        if(this.mFlot == null) {
            this.mFlot = new mstar.flot(cons.mChartContainer,this.getChartOption("miniChart"));    
        }
        var ticks = this.chartData.MiniChartData.length?this.getTicks(this.chartData.MiniChartData[0],"d"):[];
		this.mFlot.setOption({xaxis:{tickSize:null,ticks:ticks}});
        this.mFlot.init(this.chartData.MiniChartData);
    },
	exportDataToExcel:function(){
		if(this.mainTicker==""||this.mainTicker==null)return;
		var symbols = [this.mainTicker],st = RTQ_ChartUtil.formatDate(this.startDate),ed = RTQ_ChartUtil.formatDate(this.endDate);
		if(this.compairTickers.length)symbols = symbols.concat(this.compairTickers)
		var days=null,ty;
		if(this.zoomRange==1 ){  // one day
			days=1, ty = 0;
		}else if(this.zoomRange==2){ // five day
			days=5, ty = 0;
		}else if(this._frequencyIndexMap[this.frequency]<1){
			ty = 2;
		}else {
			ty = 1;
		}
		GB_ChartDataManager.exportDataToExcel(symbols,ty,st,ed,this._frequencyMap[this.frequency],days);
	},
	fileMenuCallback:function(val){  // handler the file menu in windows click event.
		if(val=="export"){  // export data to excel.
			this.exportDataToExcel();
		}
	}
});

        
